Unlike ItemExists(), HasItem() does not imply that a database query is performed to check whether there is a row for that Item.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/ObjectModel/Collection.pm | 16 ++++++++++------ testbot/lib/WineTestBot/Activity.pm | 8 ++++---- 2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/testbot/lib/ObjectModel/Collection.pm b/testbot/lib/ObjectModel/Collection.pm index 93a4502ef..bec5b1c5c 100644 --- a/testbot/lib/ObjectModel/Collection.pm +++ b/testbot/lib/ObjectModel/Collection.pm @@ -325,7 +325,7 @@ sub GetItem($$) my ($self, $Key) = @_;
return undef if (!defined $Key); - return $self->{Items}{$Key} if (defined $self->{Items}{$Key}); + return $self->{Items}{$Key} if (exists $self->{Items}{$Key});
# The Item is not present in this Collection. # See if another in-scope Collection loaded it already. @@ -352,16 +352,20 @@ sub GetItem($$) =pod =over 12
-=item C<ItemExists()> +=item C<HasItem()>
-Returns true if the specified item is present in the collection, that is if it -either matches the specified filter, or has been explicitly loaded through -GetItem(). +Returns true if the specified item is present in the collection. + +Note that unlike GetItem() this does not query the database to check if it +contains a matching item. Instead it only checks whether the Collection +already contains a matching Item, which would mean it was either loaded +because it either matches the Collection filter, or because of a GetItem() +call.
=back =cut
-sub ItemExists($$) +sub HasItem($$) { my ($self, $Key) = @_;
diff --git a/testbot/lib/WineTestBot/Activity.pm b/testbot/lib/WineTestBot/Activity.pm index b82d265f8..53aff0582 100644 --- a/testbot/lib/WineTestBot/Activity.pm +++ b/testbot/lib/WineTestBot/Activity.pm @@ -159,7 +159,7 @@ sub GetActivity($;$) { # Ignore retired / deleted VMs my ($RecordName, $RecordHost) = split / /, $Record->Name; - next if (!$VMs->ItemExists($RecordName)); + next if (!$VMs->HasItem($RecordName));
my $StatusVMs = ( $Group->{statusvms} ||= {} ); my $VMStatus = ( $StatusVMs->{$RecordName} ||= {} ); @@ -202,7 +202,7 @@ sub GetActivity($;$) elsif ($Record->Type eq "vmresult") { my ($RecordName, $RecordHost) = split / /, $Record->Name; - next if (!$VMs->ItemExists($RecordName)); + next if (!$VMs->HasItem($RecordName));
my $ResultVMs = ( $Group->{resultvms} ||= {} ); my $VMResult = ( $ResultVMs->{$RecordName} ||= {} ); @@ -362,7 +362,7 @@ sub GetStatistics($;$) foreach my $Task (@{$Tasks->GetItems()}) { my $HostStats; - if ($VMs->ItemExists($Task->VM->GetKey())) + if ($VMs->HasItem($Task->VM->GetKey())) { my $Host = $Task->VM->GetHost(); $HostStats = ($HostsStats->{items}->{$Host} ||= {}); @@ -389,7 +389,7 @@ sub GetStatistics($;$) { my $ReportSize = -s $ReportFileName; _AddFullStat($GlobalStats, "$StepType.size", $ReportSize, undef, $Task); - if ($VMs->ItemExists($Task->VM->GetKey())) + if ($VMs->HasItem($Task->VM->GetKey())) { my $VMStats = ($VMsStats->{items}->{$Task->VM->Name} ||= {}); _AddFullStat($VMStats, "report.size", $ReportSize, undef, $Task);