Use faster query to determine number of running builds

The previous query

  select count(*) from builds b left join buildsteps s on s.build = b.id where busy = 1 and finished = 0

is suddenly taking several minutes. Probably PostgreSQL decided to use
a suboptimal query plan.
This commit is contained in:
Eelco Dolstra 2016-03-16 13:41:43 +01:00
parent 405a43c171
commit 520c8a5826

View file

@ -45,9 +45,8 @@ sub begin :Private {
}
if (scalar(@args) == 0 || $args[0] ne "static") {
$c->stash->{nrRunningBuilds} = $c->model('DB::Builds')->search(
{ finished => 0, 'buildsteps.busy' => 1 },
{ join => 'buildsteps', select => ["id"], distinct => 1 })->count();
$c->stash->{nrRunningBuilds} = $c->model('DB')->schema->storage->dbh->selectrow_array(
"select count(distinct build) from buildsteps where busy = 1");
$c->stash->{nrQueuedBuilds} = $c->model('DB::Builds')->search({ finished => 0 })->count();
}