Commit 32466314 authored by Dave Lawrence's avatar Dave Lawrence

Bug 945535 - When loading bugs with large number of attachments,…

Bug 945535 - When loading bugs with large number of attachments, $bug->attachments reloads all flags for each attachment even if preloaded r=LpSolit,a=sgreen
parent 05efc5cc
...@@ -45,6 +45,7 @@ use Bugzilla::Hook; ...@@ -45,6 +45,7 @@ use Bugzilla::Hook;
use File::Copy; use File::Copy;
use List::Util qw(max); use List::Util qw(max);
use Storable qw(dclone);
use parent qw(Bugzilla::Object); use parent qw(Bugzilla::Object);
...@@ -653,23 +654,27 @@ sub get_attachments_by_bug { ...@@ -653,23 +654,27 @@ sub get_attachments_by_bug {
my $attachments = Bugzilla::Attachment->new_from_list($attach_ids); my $attachments = Bugzilla::Attachment->new_from_list($attach_ids);
$_->{bug} = $bug foreach @$attachments; $_->{bug} = $bug foreach @$attachments;
# To avoid $attachment->flags to run SQL queries itself for each # To avoid $attachment->flags and $attachment->flag_types running SQL queries
# attachment listed here, we collect all the data at once and # themselves for each attachment listed here, we collect all the data at once and
# populate $attachment->{flags} ourselves. # populate $attachment->{flag_types} ourselves. We also load all attachers and
# We also load all attachers and datasizes at once for the same reason. # datasizes at once for the same reason.
if ($vars->{preload}) { if ($vars->{preload}) {
# Preload flags. # Preload flag types and flags
$_->{flags} = [] foreach @$attachments; my $vars = { target_type => 'attachment',
my %att = map { $_->id => $_ } @$attachments; product_id => $bug->product_id,
component_id => $bug->component_id,
my $flags = Bugzilla::Flag->match({ bug_id => $bug->id, attach_id => $attach_ids };
target_type => 'attachment' }); my $flag_types = Bugzilla::Flag->_flag_types($vars);
# Exclude flags for private attachments you cannot see.
@$flags = grep {exists $att{$_->attach_id}} @$flags;
push(@{$att{$_->attach_id}->{flags}}, $_) foreach @$flags; foreach my $attachment (@$attachments) {
$attachments = [sort {$a->id <=> $b->id} values %att]; $attachment->{flag_types} = [];
my $new_types = dclone($flag_types);
foreach my $new_type (@$new_types) {
$new_type->{flags} = [ grep($_->attach_id == $attachment->id,
@{ $new_type->{flags} }) ];
push(@{ $attachment->{flag_types} }, $new_type);
}
}
# Preload attachers. # Preload attachers.
my %user_ids = map { $_->{submitter_id} => 1 } @$attachments; my %user_ids = map { $_->{submitter_id} => 1 } @$attachments;
...@@ -689,6 +694,7 @@ sub get_attachments_by_bug { ...@@ -689,6 +694,7 @@ sub get_attachments_by_bug {
# Force the size of attachments not in the DB to be recalculated. # Force the size of attachments not in the DB to be recalculated.
$_->{datasize} = $sizes->{$_->id}->{datasize} || undef foreach @$attachments; $_->{datasize} = $sizes->{$_->id}->{datasize} || undef foreach @$attachments;
} }
return $attachments; return $attachments;
} }
......
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