diff mbox series

[OSSTEST,09/60] history reporting (nfc): Provide cacheable_fn

Message ID 20200814172205.9624-10-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show
Series Speed up sg-report-job-history | expand

Commit Message

Ian Jackson Aug. 14, 2020, 5:21 p.m. UTC
Prep work.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 sg-report-host-history | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/sg-report-host-history b/sg-report-host-history
index f37dd4a2..90369ce4 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 ($) {