@@ -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";
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(-)