Split timeSpent query into 2 separate queries, as postgresql isn't able to figure out a decent query plan. With 120k jobs in queue, this makes some queries go from 100s to 1-2s.

This commit is contained in:
Eelco Dolstra 2015-05-01 12:28:29 +02:00
parent d9ab964203
commit e003665146

View file

@ -148,7 +148,14 @@ sub checkBuilds {
if (!defined $timeSpent) { if (!defined $timeSpent) {
$timeSpent = $jobset->builds->search( $timeSpent = $jobset->builds->search(
{ }, { },
{ where => \ ("(finished = 0 or (me.stoptime >= " . (time() - $windowSize) . "))") { where => \ ("(finished = 0)")
, join => 'buildsteps'
, select => \ "sum(coalesce(buildsteps.stoptime, ${\time}) - buildsteps.starttime)"
, as => "sum" })->single->get_column("sum") // 0;
$timeSpent += $jobset->builds->search(
{ },
{ where => \ ("(me.stoptime >= " . (time() - $windowSize) . ")")
, join => 'buildsteps' , join => 'buildsteps'
, select => \ "sum(coalesce(buildsteps.stoptime, ${\time}) - buildsteps.starttime)" , select => \ "sum(coalesce(buildsteps.stoptime, ${\time}) - buildsteps.starttime)"
, as => "sum" })->single->get_column("sum") // 0; , as => "sum" })->single->get_column("sum") // 0;