From 034d50069b195478c58487b61109aabdc76a16bf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 15 Apr 2012 22:11:20 +0000 Subject: [PATCH] Speed up the jobset eval list a bit --- src/lib/Hydra/Controller/Jobset.pm | 33 +++++++++++++++--------------- src/root/common.tt | 10 ++++----- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index 9b9a4897..5b105786 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -330,23 +330,18 @@ sub getEvals { my @evals = $c->stash->{jobset}->jobsetevals->search( { hasnewbuilds => 1 }, - { order_by => "id DESC" - , '+select' => # !!! Slow - should precompute this. - [ "(select count(*) from JobsetEvalMembers where eval = me.id)" - , "(select count(*) from JobsetEvalMembers where eval = me.id and exists(select 1 from Builds b where b.id = build and b.finished = 0))" - , "(select count(*) from JobsetEvalMembers where eval = me.id and exists(select 1 from Builds b where b.id = build and b.finished = 1))" - , "(select count(*) from JobsetEvalMembers where eval = me.id and exists(select 1 from Builds b where b.id = build and b.finished = 1 and b.buildStatus = 0))" - ] - , '+as' => [ "nrBuilds", "nrScheduled", "nrFinished", "nrSucceeded" ] - , rows => $rows + 1 - , offset => $offset - }); + { order_by => "id DESC", rows => $rows + 1, offset => $offset }); my @res = (); my $prevInputs = []; + my $prev; for (my $n = scalar @evals - 1; $n >= 0; $n--) { my $cur = $evals[$n]; - my $prev = $evals[$n + 1]; + + # Get stats for this eval. + my $nrBuilds = $cur->jobsetevalmembers->count; + my $nrScheduled = $cur->builds->search({finished => 0})->count; + my $nrSucceeded = $cur->builds->search({finished => 1, buildStatus => 0})->count; # Compute what inputs changed between each eval. my $curInputs = [ $cur->jobsetevalinputs->search( @@ -361,15 +356,21 @@ sub getEvals { if !defined $p || $input->revision ne $p->revision || $input->type ne $p->type || $input->uri ne $p->uri; } $prevInputs = $curInputs; - - push @res, + + my $e = { eval => $cur - , diff => defined $prev ? $cur->get_column("nrSucceeded") - $prev->get_column("nrSucceeded") : 0 + , nrBuilds => $nrBuilds + , nrScheduled => $nrScheduled + , nrSucceeded => $nrSucceeded + , nrFailed => $nrBuilds - $nrSucceeded - $nrScheduled + , diff => defined $prev ? $nrSucceeded - $prev->{nrSucceeded} : 0 , changedInputs => [ @changedInputs ] }; + push @res, $e if $n < $rows; + $prev = $e; } - return [(reverse @res)[0..$rows - 1]]; + return [reverse @res]; } diff --git a/src/root/common.tt b/src/root/common.tt index 9345c4de..6e6a325c 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -439,16 +439,16 @@ [%- END -%] - [% eval.get_column('nrSucceeded') %] - [% eval.get_column('nrBuilds') - eval.get_column('nrSucceeded') - eval.get_column('nrScheduled') %] - [% IF eval.get_column('nrScheduled') > 0 %] - [% eval.get_column('nrScheduled') %] + [% e.nrSucceeded %] + [% e.nrFailed %] + [% IF e.nrScheduled > 0 %] + [% e.nrScheduled %] [% END %] [%- IF e.diff > 0 -%] +[% e.diff %] - [%- ELSIF e.diff < 0 && eval.get_column('nrScheduled') == 0 -%] + [%- ELSIF e.diff < 0 && e.nrScheduled == 0 -%] [% e.diff %] [%- END -%]