Skip to content

Commit

Permalink
Merge pull request #3972 from perlpunk/group-overview-opt
Browse files Browse the repository at this point in the history
Optimize group_overview: don't fetch bugdetails where not needed
  • Loading branch information
mergify[bot] committed Jun 22, 2021
2 parents 2ce59c6 + 72af7d9 commit 02699d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lib/OpenQA/Schema/ResultSet/Comments.pm
Expand Up @@ -43,17 +43,23 @@ sub referenced_bugs {

=over 4
=item comment_data_for_jobs($jobs)
=item comment_data_for_jobs($jobs, $args)
Return a hashref with bugrefs, labels and the number of regular comments per job ID.
You can pass an additional argument C<bugdetails> if necessary:
$self->comment_data_for_jobs($jobs, {bugdetails => 1});
if you need the Bug objects themselves.
=back
=cut

sub comment_data_for_jobs ($self, $jobs) {
sub comment_data_for_jobs ($self, $jobs, $args = {}) {
my @job_ids = map { $_->id } ref $jobs eq 'ARRAY' ? @$jobs : $jobs->all;
my $comments = $self->search({job_id => {in => \@job_ids}}, {order_by => 'me.id'});
my $comments = $self->search({job_id => {in => \@job_ids}}, {order_by => 'me.id', select => [qw(text job_id)]});
my $bugs = $self->result_source->schema->resultset('Bugs');

my (%res, %bugdetails);
Expand All @@ -62,7 +68,7 @@ sub comment_data_for_jobs ($self, $jobs) {
if (@$bugrefs) {
my $bugs_of_job = ($res->{bugs} //= {});
for my $bug (@$bugrefs) {
$bugdetails{$bug} = $bugs->get_bug($bug) unless exists $bugdetails{$bug};
$bugdetails{$bug} ||= $bugs->get_bug($bug) if $args->{bugdetails};
$bugs_of_job->{$bug} = 1;
}
$res->{bugdetails} = \%bugdetails;
Expand Down
4 changes: 2 additions & 2 deletions lib/OpenQA/WebAPI/Controller/Test.pm
Expand Up @@ -470,7 +470,7 @@ sub job_next_previous_ajax {
&& $each->t_finished ? $self->format_time_duration($each->t_finished - $each->t_started) : 0,
});
}
my $comment_data = $schema->resultset('Comments')->comment_data_for_jobs(\@jobs);
my $comment_data = $schema->resultset('Comments')->comment_data_for_jobs(\@jobs, {bugdetails => 1});
for my $data (@data) {
my $id = $data->{id};
my $comment_info = $comment_data->{$id};
Expand Down Expand Up @@ -547,7 +547,7 @@ sub prepare_job_results {

# prefetch the number of available labels for those jobs
my $schema = $self->schema;
my $comment_data = $schema->resultset('Comments')->comment_data_for_jobs($jobs);
my $comment_data = $schema->resultset('Comments')->comment_data_for_jobs($jobs, {bugdetails => 1});

# prefetch test suite names from job settings
my $job_settings
Expand Down

0 comments on commit 02699d6

Please sign in to comment.