From 69e9a91bcb009eb3624ef1fbdc0f031783d26a9b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 29 Nov 2011 19:55:49 +0100 Subject: [PATCH] Fix a huge performance regression in the jobstatus page The renderBuildStatusIcon function was looking at the resultInfo and schedulingInfo of each build, causing a SQL query for every build in the result. --- src/lib/Hydra/Base/Controller/ListBuilds.pm | 12 +++++++----- src/lib/Hydra/Controller/Job.pm | 13 +++++++++---- src/lib/Hydra/Controller/Jobset.pm | 6 +++++- src/root/common.tt | 18 ++++++------------ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/lib/Hydra/Base/Controller/ListBuilds.pm b/src/lib/Hydra/Base/Controller/ListBuilds.pm index 5f3699dc..fa3784cc 100644 --- a/src/lib/Hydra/Base/Controller/ListBuilds.pm +++ b/src/lib/Hydra/Base/Controller/ListBuilds.pm @@ -16,8 +16,8 @@ sub getJobStatus { $latest = $latest->search( defined $maintainer ? { maintainers => { like => "%$maintainer%" } } : {}, - { '+select' => ["me.statusChangeId", "me.statusChangeTime"] - , '+as' => ["statusChangeId", "statusChangeTime"] + { '+select' => ["me.statusChangeId", "me.statusChangeTime", "resultInfo.buildStatus"] + , '+as' => ["statusChangeId", "statusChangeTime", "buildStatus"] , order_by => "coalesce(statusChangeTime, 0) desc" }); @@ -64,11 +64,13 @@ sub all : Chained('get_builds') PathPart { $c->stash->{resultsPerPage} = $resultsPerPage; $c->stash->{totalBuilds} = $nrBuilds; - $c->stash->{builds} = [joinWithResultInfo($c, $c->stash->{allBuilds})->search( + $c->stash->{builds} = [ joinWithResultInfo($c, $c->stash->{allBuilds})->search( { finished => 1 }, - { order_by => "timestamp DESC" + { '+select' => ["resultInfo.buildStatus"] + , '+as' => ["buildStatus"] + , order_by => "timestamp DESC" , rows => $resultsPerPage - , page => $page })]; + , page => $page }) ]; } diff --git a/src/lib/Hydra/Controller/Job.pm b/src/lib/Hydra/Controller/Job.pm index 1b4619f2..59ae2664 100644 --- a/src/lib/Hydra/Controller/Job.pm +++ b/src/lib/Hydra/Controller/Job.pm @@ -25,11 +25,16 @@ sub overview : Chained('job') PathPart('') Args(0) { #getBuildStats($c, scalar $c->stash->{job}->builds); - $c->stash->{currentBuilds} = [$c->stash->{job}->builds->search({iscurrent => 1}, { join => 'resultInfo', '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"] - , '+as' => ["releasename", "buildstatus"], order_by => 'system' })]; + $c->stash->{currentBuilds} = [$c->stash->{job}->builds->search({iscurrent => 1}, { join => 'resultInfo', '+select' => ["resultInfo.releasename", "resultInfo.buildStatus"] + , '+as' => ["releasename", "buildStatus"], order_by => 'system' })]; - $c->stash->{lastBuilds} = [$c->stash->{job}->builds->search({ finished => 1 }, { join => 'resultInfo', '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"] - , '+as' => ["releasename", "buildstatus"], order_by => 'timestamp DESC', rows => 10 })]; + $c->stash->{lastBuilds} = + [ $c->stash->{job}->builds->search({ finished => 1 }, + { join => 'resultInfo', + , '+select' => ["resultInfo.releasename", "resultInfo.buildStatus"] + , '+as' => ["releasename", "buildStatus"] + , order_by => 'timestamp DESC', rows => 10 + }) ]; $c->stash->{runningBuilds} = [$c->stash->{job}->builds->search({busy => 1}, { join => ['schedulingInfo', 'project'] , order_by => ["priority DESC", "timestamp"] , '+select' => ['project.enabled', 'schedulingInfo.priority', 'schedulingInfo.disabled', 'schedulingInfo.busy'] diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index 7324d3f7..11131b20 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -82,7 +82,11 @@ sub jobsetIndex { # Last builds for jobset. my $tmp = $c->stash->{jobset}->builds; $c->stash->{lastBuilds} = - [ joinWithResultInfo($c, $tmp)->search({ finished => 1 }, { order_by => "timestamp DESC", rows => 5 }) ]; + [ joinWithResultInfo($c, $tmp)->search({ finished => 1 }, + { order_by => "timestamp DESC", rows => 5 + , '+select' => ["resultInfo.buildStatus"] + , '+as' => ["buildStatus"] + }) ]; } sub index : Chained('jobset') PathPart('') Args(0) { diff --git a/src/root/common.tt b/src/root/common.tt index 66411c5b..9bd21fc3 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -100,7 +100,7 @@ onclick="if(event.which == 2) return true ; window.location = '[% c.uri_for('/build' build.id) %]'"> [% IF !hideResultInfo %] - [% INCLUDE renderBuildStatusIcon size=16 %] + [% INCLUDE renderBuildStatusIcon size=16 busy=(showSchedulingInfo ? 1 : 0) buildstatus=build.get_column('buildStatus') %] [% END %] [% build.id %] @@ -203,9 +203,9 @@ [% INCLUDE renderFullJobNameOfBuild build=build %] build [% build.id %][% -%] [% END %] -[% BLOCK renderBuildStatusIcon; %] - [% finished = build != undef ? build.finished : 1 %] - [% busy = build != undef ? build.schedulingInfo.busy : 0 %] +[% BLOCK renderBuildStatusIcon %] + [% finished = build != undef ? build.finished : 1 %] + [% busy = busy != undef ? busy : build.schedulingInfo.busy %] [% buildstatus = buildstatus != undef ? buildstatus : build.resultInfo.buildstatus %] [% IF finished %] [% IF buildstatus == 0 %] @@ -230,30 +230,24 @@ [% END %] [% END %] -[% BLOCK renderStatus; %] +[% BLOCK renderStatus %] [% IF build.finished %] + [% INCLUDE renderBuildStatusIcon size=16 %] [% IF build.resultInfo.buildstatus == 0 %] - [% INCLUDE renderBuildStatusIcon size=16 %] Success [% ELSIF build.resultInfo.buildstatus == 1 %] - [% INCLUDE renderBuildStatusIcon size=16 %] Build returned a non-zero exit code [% ELSIF build.resultInfo.buildstatus == 2 %] - [% INCLUDE renderBuildStatusIcon size=16 %] A dependency of the build failed [% ELSIF build.resultInfo.buildstatus == 4 %] - [% INCLUDE renderBuildStatusIcon size=16 %] Cancelled by user [% ELSIF build.resultInfo.buildstatus == 5 %] - [% INCLUDE renderBuildStatusIcon size=16 %] Build inhibited because a dependency previously failed to build [% failedDep = build.resultInfo.failedDep %] (namely, [% failedDep.outpath %]) [% ELSIF build.resultInfo.buildstatus == 6 %] - [% INCLUDE renderBuildStatusIcon size=16 %] Build failed (with result) [% ELSE %] - [% INCLUDE renderBuildStatusIcon size=16 %] Build failed (see below) [% END %]