From: Max Kanat-Alexander Date: Sun, 14 Mar 2010 00:41:44 +0000 (-0800) Subject: Bug 552168: Speed up comment display by pre-loading all Bugzilla::User X-Git-Tag: bugzilla-3.6~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a1ce53b4163dcb296d1ca919ec3b1f0056630a4;p=thirdparty%2Fbugzilla.git Bug 552168: Speed up comment display by pre-loading all Bugzilla::User objects for the comment authors, for the whole list, all at once. r=LpSolit, a=LpSolit --- diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index fd28b5b82c..f41a242f95 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -2689,6 +2689,7 @@ sub comments { $comment->{count} = $count++; $comment->{bug} = $self; } + Bugzilla::Comment->preload($self->{'comments'}); } my @comments = @{ $self->{'comments'} }; diff --git a/Bugzilla/Comment.pm b/Bugzilla/Comment.pm index 58e1e7a733..cbdddba3c0 100644 --- a/Bugzilla/Comment.pm +++ b/Bugzilla/Comment.pm @@ -27,6 +27,7 @@ use base qw(Bugzilla::Object); use Bugzilla::Attachment; use Bugzilla::Constants; use Bugzilla::Error; +use Bugzilla::User; use Bugzilla::Util; ############################### @@ -74,6 +75,18 @@ sub update { return $changes; } +# Speeds up displays of comment lists by loading all ->author objects +# at once for a whole list. +sub preload { + my ($class, $comments) = @_; + my %user_ids = map { $_->{who} => 1 } @$comments; + my $users = Bugzilla::User->new_from_list([keys %user_ids]); + my %user_map = map { $_->id => $_ } @$users; + foreach my $comment (@$comments) { + $comment->{author} = $user_map{$comment->{who}}; + } +} + ############################### #### Accessors ###### ###############################