From b6d1cc32f75d47437e382caccfccc5b2d98af765 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Mon, 3 Jan 2011 18:09:42 -0800 Subject: Bug 595410: Make it faster to display a bug that has a lot of dependencies. r=LpSolit, a=LpSolit --- Bugzilla/Bug.pm | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'Bugzilla/Bug.pm') diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index f3a28658a..398843009 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -472,6 +472,26 @@ sub match { return $class->SUPER::match(@_); } +# Helps load up information for bugs for show_bug.cgi and other situations +# that will need to access info on lots of bugs. +sub preload { + my ($class, $bugs) = @_; + my $user = Bugzilla->user; + + # It would be faster but MUCH more complicated to select all the + # deps for the entire list in one SQL statement. If we ever have + # a profile that proves that that's necessary, we can switch over + # to the more complex method. + my @all_dep_ids; + foreach my $bug (@$bugs) { + push(@all_dep_ids, @{ $bug->blocked }, @{ $bug->dependson }); + } + @all_dep_ids = uniq @all_dep_ids; + # If we don't do this, can_see_bug will do one call per bug in + # the dependency lists, during get_bug_link in Bugzilla::Template. + $user->visible_bugs(\@all_dep_ids); +} + sub possible_duplicates { my ($class, $params) = @_; my $short_desc = $params->{summary}; @@ -2302,6 +2322,8 @@ sub set_dependencies { detaint_natural($_) foreach (@$dependson, @$blocked); $self->{'dependson'} = $dependson; $self->{'blocked'} = $blocked; + delete $self->{depends_on_obj}; + delete $self->{blocks_obj}; } sub _clear_dup_id { $_[0]->{dup_id} = undef; } sub set_dup_id { @@ -3003,6 +3025,12 @@ sub blocked { return $self->{'blocked'}; } +sub blocks_obj { + my ($self) = @_; + $self->{blocks_obj} ||= $self->_bugs_in_order($self->blocked); + return $self->{blocks_obj}; +} + sub bug_group { my ($self) = @_; return join(', ', (map { $_->name } @{$self->groups_in})); @@ -3096,6 +3124,12 @@ sub dependson { return $self->{'dependson'}; } +sub depends_on_obj { + my ($self) = @_; + $self->{depends_on_obj} ||= $self->_bugs_in_order($self->dependson); + return $self->{depends_on_obj}; +} + sub flag_types { my ($self) = @_; return $self->{'flag_types'} if exists $self->{'flag_types'}; @@ -3496,6 +3530,15 @@ sub EmitDependList { return $list_ref; } +# Creates a lot of bug objects in the same order as the input array. +sub _bugs_in_order { + my ($self, $bug_ids) = @_; + my $bugs = $self->new_from_list($bug_ids); + my %bug_map = map { $_->id => $_ } @$bugs; + my @result = map { $bug_map{$_} } @$bug_ids; + return \@result; +} + # Get the activity of a bug, starting from $starttime (if given). # This routine assumes Bugzilla::Bug->check has been previously called. sub GetBugActivity { -- cgit v1.2.3-24-g4f1b