]> xenbits.xensource.com Git - osstest.git/commitdiff
history reporting (nfc): Provide cacheable_fn
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 4 Aug 2020 17:17:08 +0000 (18:17 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Wed, 19 Aug 2020 10:41:18 +0000 (11:41 +0100)
Prep work.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
sg-report-host-history

index f37dd4a266928df975075bf9e7f0616492b0d3d8..90369ce4d9ce0260982b03a57fdae0454720f684 100755 (executable)
@@ -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 ($) {