From 30e2b9046ad9771717c9b2d14a3f7a5094ff48c4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 3 Apr 2012 11:28:59 +0200 Subject: [PATCH] Cleanup --- src/lib/Hydra/Controller/Jobset.pm | 8 ++------ src/lib/Hydra/Controller/JobsetEval.pm | 6 +----- src/lib/Hydra/Helper/CatalystUtils.pm | 12 ++++++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index 92525592..4a580d08 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -362,12 +362,8 @@ sub evals : Chained('jobset') PathPart('evals') Args(0) { # Redirect to the latest finished evaluation of this jobset. sub latest_eval : Chained('jobset') PathPart('latest-eval') { my ($self, $c, @args) = @_; - my ($eval) = $c->stash->{jobset}->jobsetevals->search( - { hasnewbuilds => 1 }, - { order_by => "id DESC", rows => 1 - , where => \ "not exists (select 1 from JobsetEvalMembers m join Builds b on m.build = b.id where m.eval = me.id and b.finished = 0)" - }); - notFound($c, "No evaluation found.") unless defined $eval; + my $eval = getLatestFinishedEval($c, $c->stash->{jobset}) + or notFound($c, "No evaluation found."); my $uri = $c->uri_for($c->controller('JobsetEval')->action_for("view"), [$eval->id]); $uri .= "/" . join("/", @args) if scalar @args > 0; $c->res->redirect($uri); diff --git a/src/lib/Hydra/Controller/JobsetEval.pm b/src/lib/Hydra/Controller/JobsetEval.pm index 39417678..76c85feb 100644 --- a/src/lib/Hydra/Controller/JobsetEval.pm +++ b/src/lib/Hydra/Controller/JobsetEval.pm @@ -38,11 +38,7 @@ sub view : Chained('eval') PathPart('') Args(0) { } elsif (defined $compare && $compare =~ /^($jobNameRE)$/) { my $j = $c->stash->{project}->jobsets->find({name => $compare}) or notFound($c, "Jobset $compare doesn't exist."); - ($eval2) = $j->jobsetevals->search( - { hasnewbuilds => 1 }, - { order_by => "id DESC", rows => 1 - , where => \ "not exists (select 1 from JobsetEvalMembers m join Builds b on m.build = b.id where m.eval = me.id and b.finished = 0)" - }); + $eval2 = getLatestFinishedEval($c, $j); } else { ($eval2) = $eval->jobset->jobsetevals->search( { hasnewbuilds => 1, id => { '<', $eval->id } }, diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index da269c93..80c391ab 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -12,6 +12,7 @@ our @EXPORT = qw( error notFound requireLogin requireProjectOwner requireAdmin requirePost isAdmin isProjectOwner trim + getLatestFinishedEval $pathCompRE $relPathRE $relNameRE $jobNameRE $systemRE @buildListColumns ); @@ -168,6 +169,17 @@ sub trim { } +sub getLatestFinishedEval { + my ($c, $jobset) = @_; + my ($eval) = $jobset->jobsetevals->search( + { hasnewbuilds => 1 }, + { order_by => "id DESC", rows => 1 + , where => \ "not exists (select 1 from JobsetEvalMembers m join Builds b on m.build = b.id where m.eval = me.id and b.finished = 0)" + }); + return $eval; +} + + # Security checking of filenames. Readonly our $pathCompRE => "(?:[A-Za-z0-9-\+\._][A-Za-z0-9-\+\._]*)"; Readonly our $relPathRE => "(?:$pathCompRE(?:/$pathCompRE)*)";