From 12c1d901359efd04ef8d9185490b014acf3249c4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 23 Mar 2009 13:52:24 +0000 Subject: [PATCH] * Add some DB indices to make the /releases page much faster. * Reduce the number of DB queries for the /all and /jobstatus pages. * Show the Hydra version number. --- release.nix | 3 ++- src/lib/Hydra/Base/Controller/ListBuilds.pm | 8 +++++++- src/lib/Hydra/Controller/Root.pm | 19 ++++++++++++------- src/lib/Hydra/Helper/CatalystUtils.pm | 5 ++++- src/lib/Hydra/Helper/Nix.pm | 9 ++++++--- src/root/common.tt | 4 ++-- src/root/layout.tt | 3 ++- src/root/releases.tt | 2 +- src/sql/hydra.sql | 5 +++++ 9 files changed, 41 insertions(+), 17 deletions(-) diff --git a/release.nix b/release.nix index b1c4c64c..24431dae 100644 --- a/release.nix +++ b/release.nix @@ -105,7 +105,8 @@ let wrapProgram $i \ --prefix PERL5LIB ':' $out/libexec/hydra/lib:$PERL5LIB \ --set PATH $out/bin:$hydraPath \ - --set HYDRA_HOME $out/libexec/hydra + --set HYDRA_HOME $out/libexec/hydra \ + --set HYDRA_RELEASE ${tarball.version} done ensureDir $out/share/doc/hydra/manual diff --git a/src/lib/Hydra/Base/Controller/ListBuilds.pm b/src/lib/Hydra/Base/Controller/ListBuilds.pm index 3c7143ea..0a80760c 100644 --- a/src/lib/Hydra/Base/Controller/ListBuilds.pm +++ b/src/lib/Hydra/Base/Controller/ListBuilds.pm @@ -34,7 +34,13 @@ sub all : Chained('get_builds') PathPart { $c->stash->{totalBuilds} = $nrBuilds; $c->stash->{builds} = [$c->stash->{allBuilds}->search( - {finished => 1}, {order_by => "timestamp DESC", rows => $resultsPerPage, page => $page})]; + { finished => 1 }, + { join => 'resultInfo' + , '+select' => ["resultInfo.buildstatus", "resultInfo.releasename"] + , '+as' => ["buildstatus", "releasename"] + , order_by => "timestamp DESC" + , rows => $resultsPerPage + , page => $page })]; } diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index bb9be77e..47dfa24c 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -15,6 +15,7 @@ sub begin :Private { my ($self, $c) = @_; $c->stash->{projects} = [$c->model('DB::Projects')->search({}, {order_by => 'displayname'})]; $c->stash->{curUri} = $c->request->uri; + $c->stash->{version} = $ENV{"HYDRA_RELEASE"} || ""; } @@ -78,11 +79,11 @@ sub getReleaseSet { my ($c, $projectName, $releaseSetName) = @_; my $project = $c->model('DB::Projects')->find($projectName); - die "Project $projectName doesn't exist." if !defined $project; + notFound($c, "Project $projectName doesn't exist.") if !defined $project; $c->stash->{project} = $project; (my $releaseSet) = $c->model('DB::ReleaseSets')->find($projectName, $releaseSetName); - die "Release set $releaseSetName doesn't exist." if !defined $releaseSet; + notFound($c, "Release set $releaseSetName doesn't exist.") if !defined $releaseSet; $c->stash->{releaseSet} = $releaseSet; (my $primaryJob) = $releaseSet->releasesetjobs->search({isprimary => 1}); @@ -101,7 +102,8 @@ sub updateReleaseSet { my ($c, $releaseSet) = @_; my $releaseSetName = trim $c->request->params->{name}; - die "Invalid release set name: $releaseSetName" unless $releaseSetName =~ /^[[:alpha:]][\w\-]*$/; + error($c, "Invalid release set name: $releaseSetName") + unless $releaseSetName =~ /^[[:alpha:]][\w\-]*$/; $releaseSet->update( { name => $releaseSetName @@ -137,7 +139,8 @@ sub updateReleaseSet { }); } - die "There must be one primary job." if $releaseSet->releasesetjobs->search({isprimary => 1})->count != 1; + error($c, "There must be one primary job.") + if $releaseSet->releasesetjobs->search({isprimary => 1})->count != 1; } @@ -184,7 +187,7 @@ sub create_releaseset :Local { my ($self, $c, $projectName, $subcommand) = @_; my $project = $c->model('DB::Projects')->find($projectName); - die "Project $projectName doesn't exist." if !defined $project; + error($c, "Project $projectName doesn't exist.") if !defined $project; $c->stash->{project} = $project; requireProjectOwner($c, $project); @@ -222,8 +225,10 @@ sub release :Local { # Note: we don't actually check whether $releaseId is a primary # build, but who cares? my $primaryBuild = $project->builds->find($releaseId, - { join => 'resultInfo', '+select' => ["resultInfo.releasename"], '+as' => ["releasename"] }); - error($c, "Release $releaseId doesn't exist.") if !defined $primaryBuild; + { join => 'resultInfo', + , '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"] + , '+as' => ["releasename", "buildstatus"] }) + or error($c, "Release $releaseId doesn't exist."); $c->stash->{release} = getRelease($primaryBuild, $jobs); } diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 6d7fc208..bb8bf942 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -55,7 +55,10 @@ sub getLatestBuilds { foreach my $system ($job->builds->search({}, {select => ['system'], distinct => 1})) { my ($build) = $job->builds->search( { finished => 1, system => $system->system, %$extraAttrs }, - { join => 'resultInfo', order_by => 'timestamp DESC', rows => 1 }); + { join => 'resultInfo', order_by => 'timestamp DESC', rows => 1 + , '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"] + , '+as' => ["releasename", "buildstatus"] + }); push @res, $build if defined $build; } } diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 0820943f..4fd7377c 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -130,7 +130,8 @@ sub getPrimaryBuildsForReleaseSet { my @primaryBuilds = $project->builds->search( { jobset => $primaryJob->get_column('jobset'), job => $primaryJob->get_column('job'), finished => 1 }, { join => 'resultInfo', order_by => "timestamp DESC" - , '+select' => ["resultInfo.releasename"], '+as' => ["releasename"] + , '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"] + , '+as' => ["releasename", "buildstatus"] , where => \ attrsToSQL($primaryJob->attrs, "me.id") }); return @primaryBuilds; @@ -158,17 +159,19 @@ sub getRelease { # as input. If there are multiple, prefer successful # ones, and then oldest. !!! order_by buildstatus is hacky ($thisBuild) = $primaryBuild->dependentBuilds->search( - { jobset => $job->get_column('jobset'), job => $job->get_column('job'), finished => 1 }, + { project => $job->get_column('project'), jobset => $job->get_column('jobset') + , job => $job->get_column('job'), finished => 1 }, { join => 'resultInfo', rows => 1 , order_by => ["buildstatus", "timestamp"] , where => \ attrsToSQL($job->attrs, "build.id") + , '+select' => ["resultInfo.buildstatus"], '+as' => ["buildstatus"] }); } if ($job->mayfail != 1) { if (!defined $thisBuild) { $status = 2 if $status == 0; # = unfinished - } elsif ($thisBuild->resultInfo->buildstatus != 0) { + } elsif ($thisBuild->get_column('buildstatus') != 0) { $status = 1; # = failed } } diff --git a/src/root/common.tt b/src/root/common.tt index d2add394..49db1e83 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -80,7 +80,7 @@ onclick="window.location = '[% c.uri_for('/build' build.id) %]'"> [% IF !hideResultInfo %] - [% IF build.resultInfo.buildstatus == 0 %] + [% IF build.get_column('buildstatus') == 0 %] Succeeded [% ELSE %] Failed @@ -94,7 +94,7 @@ [% INCLUDE renderFullJobNameOfBuild %] - [% build.resultInfo.releasename ? build.resultInfo.releasename : build.nixname %] + [% build.get_column('releasename') ? build.get_column('releasename') : build.nixname %] [% build.system %] [% date.format(build.timestamp, '%Y-%m-%d %H:%M:%S') %] [% build.description %] diff --git a/src/root/layout.tt b/src/root/layout.tt index 7509a29d..acd1fc6d 100644 --- a/src/root/layout.tt +++ b/src/root/layout.tt @@ -146,7 +146,8 @@ [% content %]