From: Ian Jackson Date: Tue, 4 Aug 2020 17:17:08 +0000 (+0100) Subject: history reporting (nfc): Provide cacheable_fn X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=68d3a2661be6313353505bd6fc81697224bf6ae2;p=osstest.git history reporting (nfc): Provide cacheable_fn Prep work. Signed-off-by: Ian Jackson --- diff --git a/sg-report-host-history b/sg-report-host-history index f37dd4a..90369ce 100755 --- a/sg-report-host-history +++ b/sg-report-host-history @@ -181,20 +181,27 @@ END our $jqcachemisses = 0; our $jqtotal = 0; -sub cacheable_query ($$$) { - my ($q, $jr, $cachekey) = @_; +sub cacheable_fn ($$$) { + my ($jr, $cachekey, $fn) = @_; $jqtotal++; $cachekey = '%'.$cachekey; my $cached = $jr->{$cachekey}; if (!$cached) { $jqcachemisses++; - $q->execute($jr->{flight}, $jr->{job}); - $cached = $q->fetchrow_hashref(); + $cached = $fn->(); $jr->{$cachekey} = $cached; } return $cached; } +sub cacheable_query ($$$) { + my ($q, $jr, $cachekey) = @_; + cacheable_fn($jr, $cachekey, sub { + $q->execute($jr->{flight}, $jr->{job}); + return $q->fetchrow_hashref(); + }); +} + our %hosts; sub mainquery ($) {