Merge pull request #969 from DeterminateSystems/builds-index-jobset-id

Builds: index on jobset_id, largely join by jobset_id
This commit is contained in:
Graham Christensen 2021-06-01 17:59:39 -04:00 committed by GitHub
commit e04dc14d94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 31 deletions

View file

@ -81,26 +81,6 @@ sub build_GET {
} }
} }
if ($build->finished) {
$c->stash->{prevBuilds} = [$c->model('DB::Builds')->search(
{ project => $c->stash->{project}->name
, jobset => $c->stash->{jobset}->name
, job => $c->stash->{job}
, 'me.system' => $build->system
, finished => 1
, buildstatus => 0
, 'me.id' => { '<=' => $build->id }
}
, { join => "actualBuildStep"
, "+select" => ["actualBuildStep.stoptime - actualBuildStep.starttime"]
, "+as" => ["actualBuildTime"]
, order_by => "me.id DESC"
, rows => 50
}
)
];
}
# Get the first eval of which this build was a part. # Get the first eval of which this build was a part.
($c->stash->{nrEvals}) = $build->jobsetevals->search({ hasnewbuilds => 1 })->count; ($c->stash->{nrEvals}) = $build->jobsetevals->search({ hasnewbuilds => 1 })->count;
$c->stash->{eval} = getFirstEval($build); $c->stash->{eval} = getFirstEval($build);

View file

@ -22,8 +22,7 @@ sub channel : Chained('/') PathPart('channel/custom') CaptureArgs(3) {
my $lastSuccessful = $c->model('DB::Builds')->find( my $lastSuccessful = $c->model('DB::Builds')->find(
{ 'eval.hasnewbuilds' => 1 { 'eval.hasnewbuilds' => 1
, project => $projectName , jobset_id => $c->stash->{jobset}->id,
, jobset => $jobsetName
, job => $channelName , job => $channelName
, buildstatus => 0 , buildstatus => 0
}, },

View file

@ -64,8 +64,7 @@ sub getNextBuild {
(my $nextBuild) = $c->model('DB::Builds')->search( (my $nextBuild) = $c->model('DB::Builds')->search(
{ finished => 1 { finished => 1
, system => $build->system , system => $build->system
, project => $build->get_column('project') , jobset_id => $build->get_column('jobset_id')
, jobset => $build->get_column('jobset')
, job => $build->get_column('job') , job => $build->get_column('job')
, 'me.id' => { '>' => $build->id } , 'me.id' => { '>' => $build->id }
}, {rows => 1, order_by => "me.id ASC"}); }, {rows => 1, order_by => "me.id ASC"});
@ -81,8 +80,7 @@ sub getPreviousSuccessfulBuild {
(my $prevBuild) = $c->model('DB::Builds')->search( (my $prevBuild) = $c->model('DB::Builds')->search(
{ finished => 1 { finished => 1
, system => $build->system , system => $build->system
, project => $build->get_column('project') , jobset_id => $build->get_column('jobset_id')
, jobset => $build->get_column('jobset')
, job => $build->get_column('job') , job => $build->get_column('job')
, buildstatus => 0 , buildstatus => 0
, 'me.id' => { '<' => $build->id } , 'me.id' => { '<' => $build->id }

View file

@ -115,10 +115,10 @@ sub jobsetOverview_ {
return $jobsets->search({}, return $jobsets->search({},
{ order_by => ["hidden ASC", "enabled DESC", "name"] { order_by => ["hidden ASC", "enabled DESC", "name"]
, "+select" => , "+select" =>
[ "(select count(*) from Builds as a where a.finished = 0 and me.project = a.project and me.name = a.jobset and a.isCurrent = 1)" [ "(select count(*) from Builds as a where me.id = a.jobset_id and a.finished = 0 and a.isCurrent = 1)"
, "(select count(*) from Builds as a where a.finished = 1 and me.project = a.project and me.name = a.jobset and buildstatus <> 0 and a.isCurrent = 1)" , "(select count(*) from Builds as a where me.id = a.jobset_id and a.finished = 1 and buildstatus <> 0 and a.isCurrent = 1)"
, "(select count(*) from Builds as a where a.finished = 1 and me.project = a.project and me.name = a.jobset and buildstatus = 0 and a.isCurrent = 1)" , "(select count(*) from Builds as a where me.id = a.jobset_id and a.finished = 1 and buildstatus = 0 and a.isCurrent = 1)"
, "(select count(*) from Builds as a where me.project = a.project and me.name = a.jobset and a.isCurrent = 1)" , "(select count(*) from Builds as a where me.id = a.jobset_id and a.isCurrent = 1)"
] ]
, "+as" => ["nrscheduled", "nrfailed", "nrsucceeded", "nrtotal"] , "+as" => ["nrscheduled", "nrfailed", "nrsucceeded", "nrtotal"]
}); });

View file

@ -426,7 +426,7 @@ sub checkBuild {
# semantically unnecessary (because they're implied by # semantically unnecessary (because they're implied by
# the eval), but they give a factor 1000 speedup on # the eval), but they give a factor 1000 speedup on
# the Nixpkgs jobset with PostgreSQL. # the Nixpkgs jobset with PostgreSQL.
{ project => $jobset->get_column('project'), jobset => $jobset->name, job => $jobName, { jobset_id => $jobset->get_column('id'), job => $jobName,
name => $firstOutputName, path => $firstOutputPath }, name => $firstOutputName, path => $firstOutputPath },
{ rows => 1, columns => ['id'], join => ['buildoutputs'] }); { rows => 1, columns => ['id'], join => ['buildoutputs'] });
if (defined $prevBuild) { if (defined $prevBuild) {

View file

@ -612,6 +612,9 @@ create index IndexBuildsOnFinished on Builds(finished) where finished = 0;
create index IndexBuildsOnIsCurrent on Builds(isCurrent) where isCurrent = 1; create index IndexBuildsOnIsCurrent on Builds(isCurrent) where isCurrent = 1;
create index IndexBuildsOnJobsetIsCurrent on Builds(project, jobset, isCurrent) where isCurrent = 1; create index IndexBuildsOnJobsetIsCurrent on Builds(project, jobset, isCurrent) where isCurrent = 1;
create index IndexBuildsOnJobIsCurrent on Builds(project, jobset, job, isCurrent) where isCurrent = 1; create index IndexBuildsOnJobIsCurrent on Builds(project, jobset, job, isCurrent) where isCurrent = 1;
create index IndexBuildsJobsetIdCurrentUnfinished on Builds(jobset_id) where isCurrent = 1 and finished = 0;
create index IndexBuildsJobsetIdCurrentFinishedStatus on Builds(jobset_id, buildstatus) where isCurrent = 1 and finished = 1;
create index IndexBuildsJobsetIdCurrent on Builds(jobset_id) where isCurrent = 1;
create index IndexBuildsOnJobset on Builds(project, jobset); create index IndexBuildsOnJobset on Builds(project, jobset);
create index IndexBuildsOnProject on Builds(project); create index IndexBuildsOnProject on Builds(project);
create index IndexBuildsOnTimestamp on Builds(timestamp); create index IndexBuildsOnTimestamp on Builds(timestamp);

5
src/sql/upgrade-75.sql Normal file
View file

@ -0,0 +1,5 @@
-- These take about 9 minutes in total on a replica of hydra.nixos.org
create index IndexBuildsJobsetIdCurrentUnfinished on Builds(jobset_id) where isCurrent = 1 and finished = 0;
create index IndexBuildsJobsetIdCurrentFinishedStatus on Builds(jobset_id, buildstatus) where isCurrent = 1 and finished = 1;
create index IndexBuildsJobsetIdCurrent on Builds(jobset_id) where isCurrent = 1;