* Set up the cache.
* Call the per-row setup hook.
* Cache the computation of $ri->{Hosts}.
* Call the per-row cache write hook.
* Finalise the cache.

Output is the same, but with cache information in the output html, and
faster.

Signed-off-by: Ian Jackson <ian.jack...@eu.citrix.com>
---
 sg-report-job-history | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/sg-report-job-history b/sg-report-job-history
index 5684ac02..9f1216a6 100755
--- a/sg-report-job-history
+++ b/sg-report-job-history
@@ -121,6 +121,10 @@ sub processjobbranch ($$$) {
            AND name LIKE '%buildjob'
 END
 
+    cache_set_task_print("$j $branch_or_all");
+    cache_set_key_cols(qw(flight status)); # we process one job per process
+    cache_read_previous("$htmlout/$html_file");
+
     print DEBUG "processjobbranch('$j',", ($bra ? "'$bra'" : 'undef'), ")\n";
 
     my %rev_grid_col;
@@ -156,13 +160,17 @@ END
 END
 
     while (my $f= $flightsq->fetchrow_hashref()) {
+       cache_row_lookup_prep(\$f);
         my $ri= report_run_getinfo($f);
 
-       $ri->{Hosts} = { };
-       $hostq->execute($f->{flight}, $f->{job});
-       while (my ($hostvar,$host) = $hostq->fetchrow_array()) {
-           $ri->{Hosts}{$hostvar} = $host;
-       }
+       $ri->{Hosts} = cacheable_fn($f, 'h', sub {
+            my %hosts;
+           $hostq->execute($f->{flight}, $f->{job});
+           while (my ($hostvar,$host) = $hostq->fetchrow_array()) {
+               $hosts{$hostvar} = $host;
+           }
+           \%hosts;
+       });
 
         my %revisions;
         add_revisions(\%revisions, $f->{flight}, $f->{job}, '');
@@ -276,8 +284,10 @@ END
            print H "</td>";
        }
        print H "</tr>\n";
+       cache_write_entry(\*H, $r->{Flight});
        $alternate ^= 1;
     }
+    cache_finish(\*H, "");
     print H "</table></body></html>\n";
     H->error and die $!;
     close H or die $!;
-- 
2.11.0


Reply via email to