[tools] testbot/web: Limit the number of days shown on the index page.

Francois Gouget fgouget at codeweavers.com
Mon Mar 1 09:15:45 CST 2021


By default only show jobs from the last 4 days to speed up generating
and loading the page. The limit can of course be changed through the
page to access older jobs.
One can also get their own default by adding '?Days=N' at the end of the
bookmarked TestBot URL.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
The 4 day default is arbitrary and could be adjusted.
Setting it too short would frequently force reloading the page with a
longer period which would be annoying. Setting it too long would
unnecessarily increase the load on the web server and slow page load.

Four days seems like a good compromise because it is the shortest time
that allows sending a patch on a friday morning, going offline for the
week-end, and checking the results on monday afternoon without hitting
the limit.
One could also pick 1 week as the default but I'm not sure it would
bring much benefit.

Here this typically reduces the page generation time to about 0.3 s 
(from 2.4 s). Obviously how much benefit one gets depends on how many 
jobs were submitted each day (in my case ~3x the normal volume on 
wtbsuite days so it's quite variable).
---
 testbot/lib/WineTestBot/Config.pm |  5 ++--
 testbot/web/index.pl              | 45 +++++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/testbot/lib/WineTestBot/Config.pm b/testbot/lib/WineTestBot/Config.pm
index a4aba2c55..fe4a27cd6 100644
--- a/testbot/lib/WineTestBot/Config.pm
+++ b/testbot/lib/WineTestBot/Config.pm
@@ -38,7 +38,7 @@ use vars qw (@ISA @EXPORT @EXPORT_OK $UseSSL $LogDir $DataDir $BinDir
              $TagPrefix $ProjectName $PatchesMailingList $LDAPServer
              $LDAPBindDN $LDAPSearchBase $LDAPSearchFilter
              $LDAPRealNameAttribute $LDAPEMailAttribute $AgentPort $Tunnel
-             $TunnelDefaults $PrettyHostNames $JobPurgeDays
+             $TunnelDefaults $PrettyHostNames $DefaultIndexDays $JobPurgeDays
              $WebHostName $RegistrationQ $RegistrationARE $MuninAPIKey);
 
 require Exporter;
@@ -55,7 +55,7 @@ require Exporter;
              $TagPrefix $ProjectName $PatchesMailingList
              $LDAPServer $LDAPBindDN $LDAPSearchBase $LDAPSearchFilter
              $LDAPRealNameAttribute $LDAPEMailAttribute $AgentPort $Tunnel
-             $TunnelDefaults $PrettyHostNames $JobPurgeDays
+             $TunnelDefaults $PrettyHostNames $DefaultIndexDays $JobPurgeDays
              $WebHostName $RegistrationQ $RegistrationARE $MuninAPIKey);
 @EXPORT_OK = qw($DbDataSource $DbUsername $DbPassword);
 
@@ -152,6 +152,7 @@ $LDAPSearchFilter = undef;
 $LDAPRealNameAttribute = undef;
 $LDAPEMailAttribute = undef;
 
+$DefaultIndexDays = 4;
 $JobPurgeDays = 30;
 
 if (!$::BuildEnv)
diff --git a/testbot/web/index.pl b/testbot/web/index.pl
index cc32bdbeb..603f295d5 100644
--- a/testbot/web/index.pl
+++ b/testbot/web/index.pl
@@ -236,8 +236,8 @@ sub GetDetailsPage($)
 
 package StatusPage;
 
-use ObjectModel::CGI::Page;
-our @ISA = qw(ObjectModel::CGI::Page);
+use ObjectModel::CGI::FreeFormPage;
+our @ISA = qw(ObjectModel::CGI::FreeFormPage);
 
 use WineTestBot::Config;
 use WineTestBot::Engine::Notify;
@@ -251,10 +251,31 @@ sub _initialize($$$)
 {
   my ($self, $Request, $RequiredRole) = @_;
 
+  $self->{Days} = $self->GetParam("Days");
+  $self->Validate();
+
   $self->{start} = Time();
   $self->SUPER::_initialize($Request, $RequiredRole);
 }
 
+sub Validate($)
+{
+  my ($self) = @_;
+
+  if (!defined $self->{Days} or !$self->{Days})
+  {
+    $self->{Days} = $DefaultIndexDays;
+  }
+  elsif ($self->{Days} !~ /^[0-9]{1,2}$/)
+  {
+    $self->{ErrField} = "Days";
+    $self->{ErrMessage} = "The number of days must be between 1 and 99";
+    $self->{Days} = $DefaultIndexDays;
+    return undef;
+  }
+  return $self->SUPER::Validate();
+}
+
 sub OutputDot($$)
 {
   my ($self, $DotColor) = @_;
@@ -328,12 +349,15 @@ sub GenerateBody($)
 
   print "<h2><a name='jobs'></a>Jobs</h2>\n";
   my $Jobs = CreateJobs();
+  my $CutOff = time() - $self->{Days} * 24 * 60 * 60;
+  $Jobs->AddFilter("Submitted", [$CutOff], ">=");
   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();
+  $Tasks->AddFilter("Started", [$CutOff], ">=");
   foreach my $Task (@{$Tasks->GetItems()})
   {
     my $JobInfo = ($JobsCollectionBlock->{JobsInfo}->{$Task->JobId} ||= {});
@@ -353,6 +377,18 @@ sub GenerateBody($)
 
   $JobsCollectionBlock->GenerateList();
 
+  print <<EOF;
+<p></p>
+<form id="Days" action='/' method='get'>
+  <div class='ItemProperty'><label>Show jobs for the past</label>
+    <div class='ItemValue'>
+      <input type='text' name='Days' maxlength='2' size='2' value='$self->{Days}' /> days
+      <input type='submit' value='Update'/>
+    </div>
+  </div>
+</form>
+EOF
+
   print "<h2><a name='vms'></a>VMs</h2>\n";
   my $VMsCollectionBlock = new VMStatusBlock(CreateVMs(), $self);
   $VMsCollectionBlock->GenerateList();
@@ -361,6 +397,11 @@ sub GenerateBody($)
   print "<p class='GeneralFooterText'>Generated in ", Elapsed($self->{start}), " s</p>\n";
 }
 
+sub OnAction($$)
+{
+  my ($self, $Action) = @_;
+  return $self->Validate() ? 1 : undef;
+}
 
 package main;
 
-- 
2.20.1




More information about the wine-devel mailing list