Commit d34b096c authored by Max Kanat-Alexander's avatar Max Kanat-Alexander

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
parent 217beee4
...@@ -2719,6 +2719,7 @@ sub comments { ...@@ -2719,6 +2719,7 @@ sub comments {
$comment->{count} = $count++; $comment->{count} = $count++;
$comment->{bug} = $self; $comment->{bug} = $self;
} }
Bugzilla::Comment->preload($self->{'comments'});
} }
my @comments = @{ $self->{'comments'} }; my @comments = @{ $self->{'comments'} };
......
...@@ -27,6 +27,7 @@ use base qw(Bugzilla::Object); ...@@ -27,6 +27,7 @@ use base qw(Bugzilla::Object);
use Bugzilla::Attachment; use Bugzilla::Attachment;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::User;
use Bugzilla::Util; use Bugzilla::Util;
############################### ###############################
...@@ -74,6 +75,18 @@ sub update { ...@@ -74,6 +75,18 @@ sub update {
return $changes; 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 ###### #### Accessors ######
############################### ###############################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment