Bug 898830: Improve loading time of show_bug.cgi

r=sgreen a=justdave


git-svn-id: svn://10.0.0.236/trunk@264964 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzrmirror%bugzilla.org 2013-08-13 18:55:07 +00:00
parent 4238ec3884
commit 008ced32b6
4 changed files with 34 additions and 40 deletions

View File

@ -1 +1 @@
8695 8696

View File

@ -126,8 +126,7 @@ the ID of the bug to which the attachment is attached
=cut =cut
sub bug_id { sub bug_id {
my $self = shift; return $_[0]->{bug_id};
return $self->{bug_id};
} }
=over =over
@ -141,11 +140,8 @@ the bug object to which the attachment is attached
=cut =cut
sub bug { sub bug {
my $self = shift;
require Bugzilla::Bug; require Bugzilla::Bug;
$self->{bug} ||= Bugzilla::Bug->new({ id => $self->bug_id, cache => 1 }); return $_[0]->{bug} //= Bugzilla::Bug->new({ id => $_[0]->bug_id, cache => 1 });
return $self->{bug};
} }
=over =over
@ -159,8 +155,7 @@ user-provided text describing the attachment
=cut =cut
sub description { sub description {
my $self = shift; return $_[0]->{description};
return $self->{description};
} }
=over =over
@ -174,8 +169,7 @@ the attachment's MIME media type
=cut =cut
sub contenttype { sub contenttype {
my $self = shift; return $_[0]->{mimetype};
return $self->{mimetype};
} }
=over =over
@ -189,9 +183,8 @@ the user who attached the attachment
=cut =cut
sub attacher { sub attacher {
my $self = shift; return $_[0]->{attacher}
return $self->{attacher} //= new Bugzilla::User({ id => $_[0]->{submitter_id}, cache => 1 });
||= new Bugzilla::User({ id => $self->{submitter_id}, cache => 1 });
} }
=over =over
@ -205,8 +198,7 @@ the date and time on which the attacher attached the attachment
=cut =cut
sub attached { sub attached {
my $self = shift; return $_[0]->{creation_ts};
return $self->{creation_ts};
} }
=over =over
@ -220,8 +212,7 @@ the date and time on which the attachment was last modified.
=cut =cut
sub modification_time { sub modification_time {
my $self = shift; return $_[0]->{modification_time};
return $self->{modification_time};
} }
=over =over
@ -235,8 +226,7 @@ the name of the file the attacher attached
=cut =cut
sub filename { sub filename {
my $self = shift; return $_[0]->{filename};
return $self->{filename};
} }
=over =over
@ -250,8 +240,7 @@ whether or not the attachment is a patch
=cut =cut
sub ispatch { sub ispatch {
my $self = shift; return $_[0]->{ispatch};
return $self->{ispatch};
} }
=over =over
@ -265,8 +254,7 @@ whether or not the attachment is obsolete
=cut =cut
sub isobsolete { sub isobsolete {
my $self = shift; return $_[0]->{isobsolete};
return $self->{isobsolete};
} }
=over =over
@ -280,8 +268,7 @@ whether or not the attachment is private
=cut =cut
sub isprivate { sub isprivate {
my $self = shift; return $_[0]->{isprivate};
return $self->{isprivate};
} }
=over =over
@ -298,8 +285,7 @@ matches, because this will return a value even if it's matched by the generic
=cut =cut
sub is_viewable { sub is_viewable {
my $self = shift; my $contenttype = $_[0]->contenttype;
my $contenttype = $self->contenttype;
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
# We assume we can view all text and image types. # We assume we can view all text and image types.
@ -373,7 +359,7 @@ the length (in bytes) of the attachment content
sub datasize { sub datasize {
my $self = shift; my $self = shift;
return $self->{datasize} if exists $self->{datasize}; return $self->{datasize} if defined $self->{datasize};
# If we have already retrieved the data, return its size. # If we have already retrieved the data, return its size.
return length($self->{data}) if exists $self->{data}; return length($self->{data}) if exists $self->{data};
@ -416,11 +402,8 @@ flags that have been set on the attachment
=cut =cut
sub flags { sub flags {
my $self = shift;
# Don't cache it as it must be in sync with ->flag_types. # Don't cache it as it must be in sync with ->flag_types.
$self->{flags} = [map { @{$_->{flags}} } @{$self->flag_types}]; return $_[0]->{flags} = [map { @{$_->{flags}} } @{$_[0]->flag_types}];
return $self->{flags};
} }
=over =over
@ -443,8 +426,7 @@ sub flag_types {
component_id => $self->bug->component_id, component_id => $self->bug->component_id,
attach_id => $self->id }; attach_id => $self->id };
$self->{flag_types} = Bugzilla::Flag->_flag_types($vars); return $self->{flag_types} = Bugzilla::Flag->_flag_types($vars);
return $self->{flag_types};
} }
############################### ###############################
@ -677,7 +659,7 @@ sub get_attachments_by_bug {
# To avoid $attachment->flags to run SQL queries itself for each # To avoid $attachment->flags to run SQL queries itself for each
# attachment listed here, we collect all the data at once and # attachment listed here, we collect all the data at once and
# populate $attachment->{flags} ourselves. # populate $attachment->{flags} ourselves.
# We also load all attachers at once for the same reason. # We also load all attachers and datasizes at once for the same reason.
if ($vars->{preload}) { if ($vars->{preload}) {
# Preload flags. # Preload flags.
$_->{flags} = [] foreach @$attachments; $_->{flags} = [] foreach @$attachments;
@ -699,6 +681,16 @@ sub get_attachments_by_bug {
foreach my $attachment (@$attachments) { foreach my $attachment (@$attachments) {
$attachment->{attacher} = $user_map{$attachment->{submitter_id}}; $attachment->{attacher} = $user_map{$attachment->{submitter_id}};
} }
# Preload datasizes.
my $sizes =
$dbh->selectall_hashref('SELECT attach_id, LENGTH(thedata) AS size
FROM attachments LEFT JOIN attach_data ON attach_id = id
WHERE bug_id = ?',
'attach_id', undef, $bug->id);
# Force the size of attachments not in the DB to be recalculated.
$_->{datasize} = $sizes->{$_->id}->{size} || undef foreach @$attachments;
} }
return $attachments; return $attachments;
} }

View File

@ -825,8 +825,7 @@ sub in_group_id {
sub groups_with_icon { sub groups_with_icon {
my $self = shift; my $self = shift;
my @groups = grep { $_->icon_url } @{ $self->groups }; return $self->{groups_with_icon} //= [grep { $_->icon_url } @{ $self->groups }];
return \@groups;
} }
sub get_products_by_permission { sub get_products_by_permission {

View File

@ -71,7 +71,10 @@ sub html_quote {
$var =~ s/"/"/g; $var =~ s/"/"/g;
# Obscure '@'. # Obscure '@'.
$var =~ s/\@/\@/g; $var =~ s/\@/\@/g;
if (Bugzilla->params->{'utf8'}) {
state $use_utf8 = Bugzilla->params->{'utf8'};
if ($use_utf8) {
# Remove the following characters because they're # Remove the following characters because they're
# influencing BiDi: # influencing BiDi:
# -------------------------------------------------------- # --------------------------------------------------------
@ -93,7 +96,7 @@ sub html_quote {
# |U+200e|Left-To-Right Mark |0xe2 0x80 0x8e | # |U+200e|Left-To-Right Mark |0xe2 0x80 0x8e |
# |U+200f|Right-To-Left Mark |0xe2 0x80 0x8f | # |U+200f|Right-To-Left Mark |0xe2 0x80 0x8f |
# -------------------------------------------------------- # --------------------------------------------------------
$var =~ s/[\x{202a}-\x{202e}]//g; $var =~ tr/\x{202a}-\x{202e}//d;
} }
return $var; return $var;
} }