Francois Gouget : testbot/web: Speed up the main index page.

Alexandre Julliard julliard at winehq.org
Thu Feb 11 15:37:05 CST 2021


Module: tools
Branch: master
Commit: 45339484508126df9c1d5c9e546d5dbc0a7ddda8
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=45339484508126df9c1d5c9e546d5dbc0a7ddda8

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Thu Feb 11 13:57:21 2021 +0100

testbot/web: Speed up the main index page.

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 at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 2486229..c88adfc 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";




More information about the wine-cvs mailing list