diff mbox series

[OSSTEST,07/13] sg-report-host-history: Store per-job query results in %$jr

Message ID 20191108185001.3319-8-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show
Series Speed up and restore host history | expand

Commit Message

Ian Jackson Nov. 8, 2019, 6:49 p.m. UTC
jobquery now looks for the subquery results in %$jr, under the
cachekey, and only runs the query if it's not found.  It then stores
the value.

We are going to persist the contents of %$jr across runs, and then
this will avoid rerunning queries needlessly.

No functional change yet.

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

Patch

diff --git a/sg-report-host-history b/sg-report-host-history
index 4c40cbec..8767b25d 100755
--- a/sg-report-host-history
+++ b/sg-report-host-history
@@ -109,11 +109,21 @@  END
     print DEBUG "MINFLIGHT $minflight\n";
 }
 
+our $jqcachemisses = 0;
+our $jqtotal = 0;
+
 sub jobquery ($$$) {
     my ($q, $jr, $cachekey) = @_;
-    my ($q, $jr) = @_;
-    $q->execute($jr->{flight}, $jr->{job});
-    return $q->fetchrow_hashref();
+    $jqtotal++;
+    $cachekey = '%'.$cachekey;
+    my $cached = $jr->{$cachekey};
+    if (!$cached) {
+	$jqcachemisses++;
+	$q->execute($jr->{flight}, $jr->{job});
+	$cached = $q->fetchrow_hashref();
+	$jr->{$cachekey} = $cached;
+    }
+    return $cached;
 }
 
 our %hosts;
@@ -215,6 +225,12 @@  END
     my $inrows = $hosts{$hostname};
     print DEBUG "FOUND ", (scalar @$inrows), " ROWS for $hostname\n";
 
+    # Each entry in @$inrows is a $jr, which is a hash
+    # It has keys for the result columns in mainquery
+    # It also has keys '%<letter>' (yes, with a literal '%')
+    # which are the results of per-job queries.
+    # The contents of $jr for each job is cached across runs. (TODO)
+
     my @rows;
     foreach my $jr (@$inrows) {
 	print DEBUG "JOB $jr->{flight}.$jr->{job} ";
@@ -377,3 +393,5 @@  foreach my $host (sort keys %hosts) {
 	reporthost $host;
     });
 }
+
+print DEBUG "JQ CACHE ".($jqtotal-$jqcachemisses)." / $jqtotal\n";