Specifically this provides read-only access to the Itemref column(s). For instance if a task refers to a VM using a VMName field, then one can now write $Task->VMName instead of $Task->VM->Name. Incidentally read accesses are also much faster, except for the first Itemref / Detailref access which has to go through the slow path to initialize the relevant hashtable.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- The speedup is about 40% for regular columns. In the Task + VM example this replaces two slow accesses with a single faster access, resulting in a ~70% speedup or even more if it avoids loading the VM object from the database. --- testbot/lib/ObjectModel/Item.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
diff --git a/testbot/lib/ObjectModel/Item.pm b/testbot/lib/ObjectModel/Item.pm index c086aec40..d47238182 100644 --- a/testbot/lib/ObjectModel/Item.pm +++ b/testbot/lib/ObjectModel/Item.pm @@ -230,10 +230,29 @@ sub AUTOLOAD
# strip fully-qualified portion my $PropertyName = substr($ObjectModel::Item::AUTOLOAD, rindex($ObjectModel::Item::AUTOLOAD, ':') + 1); + + if (!@_) + { + # Provide quick read access to all the columns and cached object refs + if (defined $self->{ColValues}{$PropertyName}) + { + return $self->{ColValues}{$PropertyName}; + } + elsif (defined $self->{Itemrefs}{$PropertyName}) + { + return $self->{Itemrefs}{$PropertyName}; + } + elsif (defined $self->{Details}{$PropertyName}) + { + return $self->{Details}{$PropertyName}; + } + } if ($PropertyName eq "DESTROY") { return; } + + # Populate the Itemrefs and Details hashtable if necessary foreach my $PropertyDescriptor (@{$self->{PropertyDescriptors}}) { if ($PropertyName eq $PropertyDescriptor->GetName())
This allows accessing these columns directly regardless of how the Item was loaded: straight from the database or through a Detailref relation. In the latter case this also simplifies accessing these columns greatly.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- This depends on the patch that provides the speedup + read access to the Itemref columns.
The end goal is actually the entire elimination (hopefully) of the master columns. This patch makes it possible to start replacing GetMasterKey() / GetMasterCols() calls with direct access to the corresponding columns. --- testbot/lib/ObjectModel/Item.pm | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/testbot/lib/ObjectModel/Item.pm b/testbot/lib/ObjectModel/Item.pm index d47238182..7d36ffa38 100644 --- a/testbot/lib/ObjectModel/Item.pm +++ b/testbot/lib/ObjectModel/Item.pm @@ -72,6 +72,14 @@ sub new($$@) $self->{PropertyDescriptors} = $Collection->{PropertyDescriptors}; $self->{MasterColNames} = $Collection->{MasterColNames}; $self->{MasterColValues} = $Collection->{MasterColValues}; + # Provide read-only access to the master column values + if ($self->{MasterColNames}) + { + foreach my $ColIndex (0..$#{$self->{MasterColNames}}) + { + $self->{ColValues}->{$self->{MasterColNames}->[$ColIndex]} = $self->{MasterColValues}->[$ColIndex]; + } + } $self->{MasterKey} = ObjectModel::Collection::ComputeMasterKey($self->{MasterColValues}); $self->{IsNew} = 1; $self->{IsModified} = !1;