Commit 9a19887e authored by Byron Jones's avatar Byron Jones

Bug 917370: large dependency trees are very slow to load

r=dkl, a=simon
parent 94929b9f
...@@ -35,9 +35,10 @@ my $bug = Bugzilla::Bug->check(scalar $cgi->param('id')); ...@@ -35,9 +35,10 @@ my $bug = Bugzilla::Bug->check(scalar $cgi->param('id'));
my $id = $bug->id; my $id = $bug->id;
local our $hide_resolved = $cgi->param('hide_resolved') ? 1 : 0; local our $hide_resolved = $cgi->param('hide_resolved') ? 1 : 0;
local our $maxdepth = $cgi->param('maxdepth') || 0; local our $maxdepth = $cgi->param('maxdepth') || 0;
if ($maxdepth !~ /^\d+$/) { $maxdepth = 0 }; if ($maxdepth !~ /^\d+$/) {
$maxdepth = 0;
}
################################################################################ ################################################################################
# Main Section # # Main Section #
...@@ -52,7 +53,7 @@ my $dependson_tree = { $id => $bug }; ...@@ -52,7 +53,7 @@ my $dependson_tree = { $id => $bug };
my $dependson_ids = {}; my $dependson_ids = {};
GenerateTree($id, "dependson", 1, $dependson_tree, $dependson_ids); GenerateTree($id, "dependson", 1, $dependson_tree, $dependson_ids);
$vars->{'dependson_tree'} = $dependson_tree; $vars->{'dependson_tree'} = $dependson_tree;
$vars->{'dependson_ids'} = [keys(%$dependson_ids)]; $vars->{'dependson_ids'} = [keys(%$dependson_ids)];
# Generate the tree of bugs that this bug blocks and a list of IDs # Generate the tree of bugs that this bug blocks and a list of IDs
# appearing in the tree. # appearing in the tree.
...@@ -60,64 +61,86 @@ my $blocked_tree = { $id => $bug }; ...@@ -60,64 +61,86 @@ my $blocked_tree = { $id => $bug };
my $blocked_ids = {}; my $blocked_ids = {};
GenerateTree($id, "blocked", 1, $blocked_tree, $blocked_ids); GenerateTree($id, "blocked", 1, $blocked_tree, $blocked_ids);
$vars->{'blocked_tree'} = $blocked_tree; $vars->{'blocked_tree'} = $blocked_tree;
$vars->{'blocked_ids'} = [keys(%$blocked_ids)]; $vars->{'blocked_ids'} = [keys(%$blocked_ids)];
$vars->{'realdepth'} = $realdepth; $vars->{'bugid'} = $id;
$vars->{'realdepth'} = $realdepth;
$vars->{'bugid'} = $id; $vars->{'maxdepth'} = $maxdepth;
$vars->{'maxdepth'} = $maxdepth; $vars->{'hide_resolved'} = $hide_resolved;
$vars->{'hide_resolved'} = $hide_resolved;
print $cgi->header(); print $cgi->header();
$template->process("bug/dependency-tree.html.tmpl", $vars) $template->process("bug/dependency-tree.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
################################################################################ # Tree Generation Functions
# Recursive Tree Generation Function #
################################################################################
sub GenerateTree { sub GenerateTree {
# Generates a dependency tree for a given bug. Calls itself recursively
# to generate sub-trees for the bug's dependencies.
my ($bug_id, $relationship, $depth, $bugs, $ids) = @_; my ($bug_id, $relationship, $depth, $bugs, $ids) = @_;
my @dependencies; # determine just the list of bug ids
if ($relationship eq 'dependson') { _generate_bug_ids($bug_id, $relationship, $depth, $ids);
@dependencies = @{$bugs->{$bug_id}->dependson}; my $bug_ids = [ keys %$ids ];
} return unless @$bug_ids;
else {
@dependencies = @{$bugs->{$bug_id}->blocked}; # load all the bugs at once
foreach my $bug (@{ Bugzilla::Bug->new_from_list($bug_ids) }) {
if (!$bug->{error}) {
$bugs->{$bug->id} = $bug;
}
} }
# Don't do anything if this bug doesn't have any dependencies. # preload bug visibility
return unless scalar(@dependencies); Bugzilla->user->visible_bugs($bug_ids);
# and generate the tree
_generate_tree($bug_id, $relationship, $depth, $bugs, $ids);
}
sub _generate_bug_ids {
my ($bug_id, $relationship, $depth, $ids) = @_;
# Record this depth in the global $realdepth variable if it's farther # Record this depth in the global $realdepth variable if it's farther
# than we've gone before. # than we've gone before.
$realdepth = max($realdepth, $depth); $realdepth = max($realdepth, $depth);
Bugzilla->user->visible_bugs(\@dependencies);
foreach my $dep_id (@dependencies) { my $dependencies = _get_dependencies($bug_id, $relationship);
# Get this dependency's record from the database and generate foreach my $dep_id (@$dependencies) {
# its sub-tree if we haven't already done so (which happens if (!$maxdepth || $depth <= $maxdepth) {
# when bugs appear in dependency trees multiple times). $ids->{$dep_id} = 1;
if (!$bugs->{$dep_id}) { _generate_bug_ids($dep_id, $relationship, $depth + 1, $ids);
$bugs->{$dep_id} = new Bugzilla::Bug($dep_id); }
GenerateTree($dep_id, $relationship, $depth+1, $bugs, $ids); }
}
sub _generate_tree {
my ($bug_id, $relationship, $depth, $bugs, $ids) = @_;
my $dependencies = _get_dependencies($bug_id, $relationship);
foreach my $dep_id (@$dependencies) {
# recurse
if (!$maxdepth || $depth < $maxdepth) {
_generate_tree($dep_id, $relationship, $depth + 1, $bugs, $ids);
} }
# Add this dependency to the list of this bug's dependencies # remove bugs according to visiblity and filters
# if it exists, if we haven't exceeded the maximum depth the user if (!Bugzilla->user->can_see_bug($dep_id)
# wants the tree to go, and if the dependency isn't resolved || ($hide_resolved && !$bugs->{$dep_id}->isopened))
# (if we're ignoring resolved dependencies).
if (!$bugs->{$dep_id}->{'error'}
&& Bugzilla->user->can_see_bug($dep_id)
&& (!$maxdepth || $depth <= $maxdepth)
&& ($bugs->{$dep_id}->isopened || !$hide_resolved))
{ {
# Due to AUTOLOAD in Bug.pm, we cannot add 'dependencies' delete $ids->{$dep_id};
# as a bug object attribute from here. }
push(@{$bugs->{'dependencies'}->{$bug_id}}, $dep_id); elsif (!grep { $_ == $dep_id } @{ $bugs->{dependencies}->{$bug_id} }) {
$ids->{$dep_id} = 1; push @{ $bugs->{dependencies}->{$bug_id} }, $dep_id;
} }
} }
} }
sub _get_dependencies {
my ($bug_id, $relationship) = @_;
my $cache = Bugzilla->request_cache->{dependency_cache} ||= {};
return $cache->{$bug_id}->{$relationship} ||=
$relationship eq 'dependson'
? Bugzilla::Bug::EmitDependList('blocked', 'dependson', $bug_id)
: Bugzilla::Bug::EmitDependList('dependson', 'blocked', $bug_id);
}
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