Skip to content

Commit

Permalink
Bug 1904151 - Updates and improvements to Bugzilla/Report/Graph.pm an…
Browse files Browse the repository at this point in the history
…d Bugzilla/API/V1/BugGraph.pm
  • Loading branch information
dklawren authored Jun 26, 2024
1 parent 7d294e0 commit e37bbe8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
27 changes: 3 additions & 24 deletions Bugzilla/API/V1/BugGraph.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,10 @@ sub graph {
);

# Remove any secure bugs that user cannot see
$report->prune_graph(sub { $user->visible_bugs($_[0]) });
$report->prune_secure;

# If we do not want resolved bugs (default) then filter those
# by passing in reference to the subroutine for filtering out
# resolved bugs
if (!$show_resolved) {
$report->prune_graph(sub { $self->_prune_resolved($_[0]) });
}
# Filter out resolved bugs
$report->prune_resolved if !$show_resolved;

if (!$ids_only) {
my $bugs = Bugzilla::Bug->new_from_list([$report->graph->vertices]);
Expand All @@ -101,21 +97,4 @@ sub graph {
return $self->render(json => $result);
}

# This method takes a set of bugs and using a single SQL statement,
# removes any bugs from the list which have a non-empty resolution (unresolved)
sub _prune_resolved {
my ($self, $bugs) = @_;
my $dbh = Bugzilla->dbh;

return $bugs if !$bugs->size;

my $placeholders = join ',', split //, '?' x $bugs->size;
my $query
= "SELECT bug_id FROM bugs WHERE (resolution IS NULL OR resolution = '') AND bug_id IN ($placeholders)";
my $filtered_bugs
= Bugzilla->dbh->selectcol_arrayref($query, undef, $bugs->elements);

return $filtered_bugs;
}

1;
41 changes: 37 additions & 4 deletions Bugzilla/Report/Graph.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use 5.10.1;
use Moo;

use Graph::Directed;
use Graph::Traversal::DFS;
use Graph::Traversal::BFS;
use PerlX::Maybe 'maybe';
use Type::Utils qw(class_type);
use Types::Standard qw(Bool Enum Int Str ArrayRef);
use Types::Standard qw(Bool Enum Int Str ArrayRef Object);
use Set::Object qw(set);

use Bugzilla;
Expand Down Expand Up @@ -104,18 +104,51 @@ sub tree {
my %nodes = map { $_ => {maybe bug => $graph->get_vertex_attributes($_)} }
$graph->vertices;

my $search = Graph::Traversal::DFS->new(
my $search = Graph::Traversal::BFS->new(
$graph,
start => $self->bug_id,
tree_edge => sub {
my ($u, $v) = @_;
$nodes{$u}{$v} = $nodes{$v};
}
);
$search->dfs;
$search->bfs;

return $nodes{$self->bug_id} || {};
}

# Remove any secure bugs that user cannot see
sub prune_secure {
my ($self, $bugs, $user) = @_;
$user ||= Bugzilla->user;

$self->prune_graph(sub {
$user->visible_bugs($_[0]);
});

return $self;
}

# This method takes a set of bugs and using a single SQL statement,
# removes any bugs from the list which have a non-empty resolution (unresolved)
sub prune_resolved {
my ($self, $bugs) = @_;

$self->prune_graph(sub {
my $bugs = $_[0];

return $bugs if !$bugs->size;

my $placeholders = join ',', split //, '?' x $bugs->size;
my $query
= "SELECT bug_id FROM bugs WHERE (resolution IS NULL OR resolution = '') AND bug_id IN ($placeholders)";
my $filtered_bugs
= Bugzilla->dbh->selectcol_arrayref($query, undef, $bugs->elements);

return $filtered_bugs;
});

return $self;
}

1;

0 comments on commit e37bbe8

Please sign in to comment.