In order to present the per-job failures tally, the main index needs to go through the tasks of every job except for the pretty rare queued jobs. But doing so one job at a time results in many SQL queries which is inefficient. So do it all at once and store the results in a hash for later use in GenerateDataCell().
Signed-off-by: Francois Gouget fgouget@codeweavers.com ---
On my test configuration generating the index page goes from about 3.4 seconds down to about 1.9. The TestBot takes between 3.4 and 4 seconds too (for a similar number of jobs).
So hopefully this will make page reloads less painful and lighten the web server load a bit.
testbot/web/index.pl | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/testbot/web/index.pl b/testbot/web/index.pl index 248622955..c88adfcb8 100644 --- a/testbot/web/index.pl +++ b/testbot/web/index.pl @@ -124,30 +124,17 @@ sub GenerateDataCell($$$$) my $HTMLStatus = $HTMLChunks{$Status} || $Status; if ($Status eq "completed" || $Status eq "boterror" || $Status eq "canceled") { - my $Failures = 0; - my $HasTestResult; - foreach my $Step (@{$Item->Steps->GetItems()}) - { - foreach my $Task (@{$Step->Tasks->GetItems()}) - { - my $TaskFailures = $Task->TestFailures; - if (defined $TaskFailures) - { - $HasTestResult = 1; - $Failures += $TaskFailures; - } - } - } - if (!$HasTestResult) + my $JobInfo = $self->{JobsInfo}->{$Item->Id}; + if (!exists $JobInfo->{TestFailures}) { print $HTMLStatus; } else { - $HTMLStatus = $Item->Status eq "completed" ? "" : "$HTMLStatus - "; - my $class = $Failures ? "testfail" : "success"; - my $s = $Failures == 1 ? "" : "s"; - print "$HTMLStatus<span class='$class'>$Failures test failure$s</span>"; + $HTMLStatus = $Status eq "completed" ? "" : "$HTMLStatus - "; + my $class = $JobInfo->{TestFailures} ? "testfail" : "success"; + my $s = $JobInfo->{TestFailures} == 1 ? "" : "s"; + print "$HTMLStatus<span class='$class'>$JobInfo->{TestFailures} test failure$s</span>"; } } else @@ -233,6 +220,7 @@ use WineTestBot::Config; use WineTestBot::Engine::Notify; use WineTestBot::Jobs; use WineTestBot::Log; +use WineTestBot::Tasks; use WineTestBot::VMs;
@@ -318,6 +306,18 @@ sub GenerateBody($) print "<h2><a name='jobs'></a>Jobs</h2>\n"; my $Jobs = CreateJobs(); my $JobsCollectionBlock = new JobStatusBlock($Jobs, $self); + + # We need to collect information about the tasks of all jobs except the + # pretty rare queued jobs. But doing so one job at a time is inefficient so + # do it all at once now and store the results in ...->{JobsInfo}. + my $Tasks = CreateTasks(); + foreach my $Task (@{$Tasks->GetItems()}) + { + my $JobInfo = ($JobsCollectionBlock->{JobsInfo}->{$Task->JobId} ||= {}); + my $TestFailures = $Task->TestFailures; + $JobInfo->{TestFailures} += $TestFailures if (defined $TestFailures); + } + $JobsCollectionBlock->GenerateList();
print "<h2><a name='vms'></a>VMs</h2>\n";