]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 552168: Speed up comment display by pre-loading all Bugzilla::User
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Sun, 14 Mar 2010 00:40:42 +0000 (16:40 -0800)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Sun, 14 Mar 2010 00:40:42 +0000 (16:40 -0800)
objects for the comment authors, for the whole list, all at once.
r=LpSolit, a=LpSolit

Bugzilla/Bug.pm
Bugzilla/Comment.pm

index 4a90c1ce7a7e90769778c84b56cca38a5ef54f9d..d435d5442ad401b7f789938db64a412084b53afb 100644 (file)
@@ -2719,6 +2719,7 @@ sub comments {
             $comment->{count} = $count++;
             $comment->{bug} = $self;
         }
+        Bugzilla::Comment->preload($self->{'comments'});
     }
     my @comments = @{ $self->{'comments'} };
 
index f19c64d78fe5d3dc049143eeaea5daf51c582143..ba33ba5f3d57d0ae21e0e796317a4bcaad61155c 100644 (file)
@@ -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      ######
 ###############################