diff options
author | mkanat%bugzilla.org <> | 2008-03-27 10:08:07 +0000 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2008-03-27 10:08:07 +0000 |
commit | 76db56635e4277804982f04b3828a8cd88093963 (patch) | |
tree | d121c6e949e0d3e8381b3f97ea1f1ff37c647b87 /Bugzilla/Product.pm | |
parent | 9345e477eccc933af13d7181cdf1a83c6a3deaa3 (diff) | |
download | bugs-76db56635e4277804982f04b3828a8cd88093963.tar bugs-76db56635e4277804982f04b3828a8cd88093963.tar.gz bugs-76db56635e4277804982f04b3828a8cd88093963.tar.bz2 bugs-76db56635e4277804982f04b3828a8cd88093963.tar.xz bugs-76db56635e4277804982f04b3828a8cd88093963.zip |
Bug 372795: Implement Bugzilla::Product::preload() to speed up query.cgi when there are many products
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=mkanat
Diffstat (limited to 'Bugzilla/Product.pm')
-rw-r--r-- | Bugzilla/Product.pm | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm index 45c489973..edc621f67 100644 --- a/Bugzilla/Product.pm +++ b/Bugzilla/Product.pm @@ -51,6 +51,32 @@ use constant DB_COLUMNS => qw( products.defaultmilestone ); +############################### +#### Constructors ##### +############################### + +# This is considerably faster than calling new_from_list three times +# for each product in the list, particularly with hundreds or thousands +# of products. +sub preload { + my ($products) = @_; + my %prods = map { $_->id => $_ } @$products; + my @prod_ids = keys %prods; + return unless @prod_ids; + + my $dbh = Bugzilla->dbh; + foreach my $field (qw(component version milestone)) { + my $classname = "Bugzilla::" . ucfirst($field); + my $objects = $classname->match({ product_id => \@prod_ids }); + + # Now populate the products with this set of objects. + foreach my $obj (@$objects) { + my $product_id = $obj->product_id; + $prods{$product_id}->{"${field}s"} ||= []; + push(@{$prods{$product_id}->{"${field}s"}}, $obj); + } + } +} ############################### #### Methods #### @@ -300,7 +326,7 @@ below. =over -=item C<components()> +=item C<components> Description: Returns an array of component objects belonging to the product. @@ -319,7 +345,7 @@ below. Returns: A hash with group id as key and hash containing a Bugzilla::Group object and the properties of group relative to the product. - + =item C<groups_mandatory_for> =over @@ -356,7 +382,7 @@ groups, in this product. =back -=item C<versions()> +=item C<versions> Description: Returns all valid versions for that product. @@ -364,7 +390,7 @@ groups, in this product. Returns: An array of Bugzilla::Version objects. -=item C<milestones()> +=item C<milestones> Description: Returns all valid milestones for that product. @@ -415,6 +441,15 @@ groups, in this product. =over +=item C<preload> + +When passed an arrayref of C<Bugzilla::Product> objects, preloads their +L</milestones>, L</components>, and L</versions>, which is much faster +than calling those accessors on every item in the array individually. + +This function is not exported, so must be called like +C<Bugzilla::Product::preload($products)>. + =item C<check_product($product_name)> Description: Checks if the product name was passed in and if is a valid |