By default filters still return the rows where the specified field is equal to one of the specified values. But now they can also be set to return rows where the field is smaller, greater, different or like one of the specified values.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/ObjectModel/Collection.pm | 6 +++--- testbot/lib/ObjectModel/DBIBackEnd.pm | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/testbot/lib/ObjectModel/Collection.pm b/testbot/lib/ObjectModel/Collection.pm index a9ec9958..86dee057 100644 --- a/testbot/lib/ObjectModel/Collection.pm +++ b/testbot/lib/ObjectModel/Collection.pm @@ -656,11 +656,11 @@ sub DeleteAll($) return undef; }
-sub AddFilter($$$) +sub AddFilter($$$;$) { - my ($self, $PropertyName, $Value) = @_; + my ($self, $PropertyName, $Values, $Type) = @_;
- $self->{Filters}{$PropertyName} = $Value; + $self->{Filters}{$PropertyName} = [($Type || "="), $Values]; }
sub GetFilters($) diff --git a/testbot/lib/ObjectModel/DBIBackEnd.pm b/testbot/lib/ObjectModel/DBIBackEnd.pm index 0594951b..565d4a8e 100644 --- a/testbot/lib/ObjectModel/DBIBackEnd.pm +++ b/testbot/lib/ObjectModel/DBIBackEnd.pm @@ -179,6 +179,16 @@ sub BuildFieldList($$) return $Fields; }
+my %_AllowedFilterTypes = ( + "=" => 1, + "<>" => 1, + "<" => 1, + "<=" => 1, + ">" => 1, + ">=" => 1, + "LIKE" => 1, +); + sub LoadCollection($$) { my ($self, $Collection) = @_; @@ -202,7 +212,16 @@ sub LoadCollection($$) $Where .= " AND "; } my $PropertyDescriptor = $Collection->GetPropertyDescriptorByName($FilterProperty); - my $FilterValues = $Filters->{$FilterProperty}; + my ($FilterType, $FilterValues) = @{$Filters->{$FilterProperty}}; + if (!$_AllowedFilterTypes{$FilterType}) + { + die "unknown '$FilterType' filter type"; + } + if (!@$FilterValues) + { + die "no values for the '$FilterType' filter"; + } + if (@$FilterValues != 1) { $Where .= "("; @@ -220,7 +239,7 @@ sub LoadCollection($$) } foreach my $ColName (@{$PropertyDescriptor->GetColNames()}) { - $Where .= "$ColName = ?"; + $Where .= "$ColName $FilterType ?"; $Data[@Data] = $self->ToDb($ColValue, $PropertyDescriptor); } }
GetActivity() now takes the number of seconds of recent activity to analyze and uses it to limit the number of records and record groups that are retrieved from the database. This can greatly speed up the analysis.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/WineTestBot/Activity.pm | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/testbot/lib/WineTestBot/Activity.pm b/testbot/lib/WineTestBot/Activity.pm index 58169aee..ba1dbb6f 100644 --- a/testbot/lib/WineTestBot/Activity.pm +++ b/testbot/lib/WineTestBot/Activity.pm @@ -43,8 +43,8 @@ require Exporter;
=item C<GetActivity()>
-Loads the records for the specified VMs and processes them to build a structure -describing the TestBot activity. +Loads the records for the specified VMs going back the specified number of +seconds and processes them to build a structure describing the TestBot activity.
Returns a list of the activity records, sorted from the oldest to the newest. Each entry contains a structure grouping all the state and event information @@ -90,19 +90,31 @@ that were processed. =back =cut
-sub GetActivity($) +sub GetActivity($;$) { - my ($VMs) = @_; + my ($VMs, $Seconds) = @_; my ($ActivityHash, $Activity, $Counters) = ({}, [], {});
### First load all the RecordGroups my $RecordGroups = CreateRecordGroups(); + if ($Seconds) + { + $RecordGroups->AddFilter("Timestamp", [time() - $Seconds], ">="); + } + my $MinId; $Counters->{recordgroups} = $RecordGroups->GetItemsCount(); foreach my $RecordGroup (sort CompareRecordGroups @{$RecordGroups->GetItems()}) { my $Group = { start => $RecordGroup->Timestamp }; $ActivityHash->{$RecordGroup->Id} = $Group; push @$Activity, $Group; + $MinId = $RecordGroup->Id if (!defined $MinId or $RecordGroup->Id < $MinId); + } + if (!defined $MinId) + { + # No activity was found in the specified period + $Counters->{records} = 0; + return ($Activity, $Counters); }
### And then load all the Records in one go @@ -111,6 +123,7 @@ sub GetActivity($)
my $Jobs = CreateJobs(); my $Records = CreateRecords(); + $Records->AddFilter("RecordGroupId", [$MinId], ">="); $Counters->{records} = $Records->GetItemsCount(); foreach my $Record (@{$Records->GetItems()}) {
This limits the time it takes to generate the activity page. One can still review the full activity log by specifying 0 as the time period to analyze. Also the page no longer self-refreshes for periods longer than the default.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/web/Activity.pl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/testbot/web/Activity.pl b/testbot/web/Activity.pl index f8b7b5ad..0b92299a 100644 --- a/testbot/web/Activity.pl +++ b/testbot/web/Activity.pl @@ -24,27 +24,37 @@ package ActivityPage; use POSIX qw(strftime); use URI::Escape;
-use ObjectModel::CGI::Page; +use ObjectModel::CGI::FreeFormPage; use WineTestBot::Config; use WineTestBot::Activity; use WineTestBot::Log; use WineTestBot::VMs;
-@ActivityPage::ISA = qw(ObjectModel::CGI::Page); +@ActivityPage::ISA = qw(ObjectModel::CGI::FreeFormPage); + +my $HOURS_DEFAULT = 24;
sub _initialize($$$) { my ($self, $Request, $RequiredRole) = @_;
$self->{start} = Time(); + $self->{hours} = $self->GetParam("Hours"); + if (!defined $self->{hours} or $self->{hours} !~ /^\d{1,3}$/) + { + $self->{hours} = $HOURS_DEFAULT; + } + $self->SUPER::_initialize($Request, $RequiredRole); }
sub GeneratePage($) { my ($self) = @_; - - $self->{Request}->headers_out->add("Refresh", "60"); + if ($self->{hours} and $self->{hours} <= $HOURS_DEFAULT) + { + $self->{Request}->headers_out->add("Refresh", "60"); + } $self->SUPER::GeneratePage(); }
@@ -88,6 +98,11 @@ sub GenerateBody($) { my ($self) = @_;
+ # Generate a custom form to let the user specify the Hours field. + $self->GenerateFormStart(); + print "<div class='ItemProperty'><label>Analyze the activity of the past <div class='ItemValue'><input type='text' name='Hours' maxlength='3' size='3' value='$self->{hours}'/></div> hours.</div>\n"; + $self->GenerateFormEnd(); + print "<h1>${ProjectName} Test Bot activity</h1>\n"; print "<div class='Content'>\n";
@@ -132,7 +147,7 @@ EOF ### Generate the HTML table with the newest record first
print "<tbody>\n"; - my ($Activity, $_Counters) = GetActivity($VMs); + my ($Activity, $_Counters) = GetActivity($VMs, $self->{hours} * 3600); for (my $Index = @$Activity; $Index--; ) { my $Group = $Activity->[$Index];