Skip to content

Commit

Permalink
api: fix /eval/X/builds requiring 5*len(builds)+1 SQL queries
Browse files Browse the repository at this point in the history
Prefetch related tables that get fetched as part of serialization to
JSON. Drop the `jobsetevals` field since making it efficient is trickier
(due to not using DBIx native relationships but instead a many_to_many
through a custom table). There is likely a way we could keep it and make
it efficient, but I'm not fluent enough in DBIx to know.

(cherry picked from commit cb10eef)
  • Loading branch information
delroth authored and Ma27 committed Mar 15, 2024
1 parent a5519b6 commit ab83857
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/lib/Hydra/Controller/JobsetEval.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ sub store_paths : Chained('evalChain') PathPart('store-paths') Args(0) {
# Return full info about all the builds in this evaluation.
sub all_builds : Chained('evalChain') PathPart('builds') Args(0) {
my ($self, $c) = @_;
my @builds = $c->stash->{eval}->builds;
my @builds = $c->stash->{eval}->builds
->search({},
{ prefetch => ['jobset', 'buildoutputs', 'buildproducts', 'buildmetrics'] });
$self->status_ok(
$c,
entity => [@builds],
Expand Down
10 changes: 2 additions & 8 deletions src/lib/Hydra/Schema/Result/Builds.pm
Original file line number Diff line number Diff line change
Expand Up @@ -568,27 +568,21 @@ makeQueries('ForJobName', "and jobset_id = (select id from jobsets j where j.nam
sub as_json {
my ($self) = @_;

# After #1093 merges this can become $self->jobset;
# However, with ->jobset being a column on master
# it seems DBIX gets a it confused.
my ($jobset) = $self->search_related('jobset')->first;

my $json = {
id => $self->get_column('id'),
finished => $self->get_column('finished'),
timestamp => $self->get_column('timestamp'),
starttime => $self->get_column('starttime'),
stoptime => $self->get_column('stoptime'),
project => $jobset->get_column('project'),
jobset => $jobset->name,
project => $self->jobset->get_column('project'),
jobset => $self->jobset->get_column('name'),
job => $self->get_column('job'),
nixname => $self->get_column('nixname'),
system => $self->get_column('system'),
priority => $self->get_column('priority'),
buildstatus => $self->get_column('buildstatus'),
releasename => $self->get_column('releasename'),
drvpath => $self->get_column('drvpath'),
jobsetevals => [ map { $_->id } $self->jobsetevals ],
buildoutputs => { map { $_->name => $_ } $self->buildoutputs },
buildproducts => { map { $_->productnr => $_ } $self->buildproducts },
buildmetrics => { map { $_->name => $_ } $self->buildmetrics },
Expand Down
1 change: 0 additions & 1 deletion t/Hydra/Controller/Build/api.t
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ subtest "validating the JSON representation of a build" => sub {
finished => 1,
id => $aggregateBuild->id,
job => "aggregate",
jobsetevals => [ $aggregateBuild->jobsetevals->first->id ],
nixname => "aggregate",
priority => 100,
releasename => undef,
Expand Down

0 comments on commit ab83857

Please sign in to comment.