From d1099104530cd52a5ecda2550d336f5addb4e71c Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Thu, 15 Oct 2009 11:13:36 +0000 Subject: [PATCH] * paging for releases page --- src/lib/Hydra/Controller/Root.pm | 15 +++++- src/lib/Hydra/Helper/Nix.pm | 87 +++++++++++++++++++++++++------- src/root/releases.tt | 10 ++++ 3 files changed, 91 insertions(+), 21 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index f29dda90..9c78a29e 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -137,7 +137,13 @@ sub releases :Local { my ($project, $releaseSet, $primaryJob, $jobs) = getReleaseSet($c, $projectName, $releaseSetName); - if (defined $subcommand && $subcommand ne "") { + my $resultsPerPage = 10; + my $page = 1; + + if (defined $subcommand && $subcommand =~ /^\d+$/ ) { + $page = int($subcommand) + } + elsif (defined $subcommand && $subcommand ne "") { requireProjectOwner($c, $project); @@ -166,8 +172,13 @@ sub releases :Local { $c->stash->{template} = 'releases.tt'; my @releases = (); - push @releases, getRelease($_, $jobs) foreach getPrimaryBuildsForReleaseSet($project, $primaryJob); + push @releases, getRelease($_, $jobs) foreach getPrimaryBuildsForReleaseSet($project, $primaryJob, $page, $resultsPerPage); + + $c->stash->{baseUri} = $c->uri_for($self->action_for("releases"), $projectName, $releaseSetName); $c->stash->{releases} = [@releases]; + $c->stash->{page} = $page; + $c->stash->{totalReleases} = getPrimaryBuildTotal($project, $primaryJob); + $c->stash->{resultsPerPage} = $resultsPerPage; } diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 1865979b..5872bb0c 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -10,7 +10,9 @@ our @EXPORT = qw( isValidPath queryPathInfo getHydraPath getHydraDBPath openHydraDB txn_do registerRoot getGCRootsDir gcRootFor - getPrimaryBuildsForReleaseSet getRelease getLatestSuccessfulRelease ); + getPrimaryBuildsForReleaseSet + getPrimaryBuildTotal + getRelease getLatestSuccessfulRelease ); sub isValidPath { @@ -146,19 +148,76 @@ sub attrsToSQL { return $query; } +sub allPrimaryBuilds { + my ($project, $primaryJob) = @_; + my $allPrimaryBuilds = $project->builds->search( + { jobset => $primaryJob->get_column('jobset'), job => $primaryJob->get_column('job'), finished => 1 }, + { join => 'resultInfo', order_by => "timestamp DESC" + , '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"] + , '+as' => ["releasename", "buildstatus"] + , where => \ attrsToSQL($primaryJob->attrs, "me.id") + }); + return $allPrimaryBuilds; +} + +sub getPrimaryBuildTotal { + my ($project, $primaryJob) = @_; + return scalar(allPrimaryBuilds($project, $primaryJob)) ; +} sub getPrimaryBuildsForReleaseSet { - my ($project, $primaryJob) = @_; - 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", "resultInfo.buildstatus"] - , '+as' => ["releasename", "buildstatus"] - , where => \ attrsToSQL($primaryJob->attrs, "me.id") + my ($project, $primaryJob, $page, $resultsPerPage) = @_; + $page = (defined $page ? int($page) : 1) || 1; + $resultsPerPage = (defined $resultsPerPage ? int($resultsPerPage) : 20) || 20; + + my @primaryBuilds = allPrimaryBuilds($project, $primaryJob)->search( {}, + { rows => $resultsPerPage + , page => $page }); + return @primaryBuilds; } +sub findLastJobForBuilds { + my ($builds, $job) = @_; + my $thisBuild; + + # Find a build of this job that had the primary build + # as input. If there are multiple, prefer successful + # ones, and then oldest. !!! order_by buildstatus is hacky + ($thisBuild) = $builds->search( + { 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"] + }); + return $thisBuild ; + +} + +sub findLastJobForPrimaryBuild { + my ($primaryBuild, $job) = @_; + my $thisBuild; + my $depBuilds; + $depBuilds = $primaryBuild->dependentBuilds; + $thisBuild = findLastJobForBuilds($depBuilds, $job) ; + +# don't do recursive yet +# if (!defined $thisBuild) { +# +# foreach my $build ($depBuilds->all) { +# $thisBuild = findLastJobForPrimaryBuild($build, $job) ; +# if (defined $thisBuild) { +# last ; +# } +# } +# } + + return $thisBuild; +} sub getRelease { my ($primaryBuild, $jobs) = @_; @@ -177,17 +236,7 @@ sub getRelease { if ($job->isprimary) { $thisBuild = $primaryBuild; } else { - # Find a build of this job that had the primary build - # as input. If there are multiple, prefer successful - # ones, and then oldest. !!! order_by buildstatus is hacky - ($thisBuild) = $primaryBuild->dependentBuilds->search( - { 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"] - }); + $thisBuild = findLastJobForPrimaryBuild($primaryBuild, $job) ; } if ($job->mayfail != 1) { diff --git a/src/root/releases.tt b/src/root/releases.tt index a0e266a0..e4407d85 100644 --- a/src/root/releases.tt +++ b/src/root/releases.tt @@ -9,6 +9,8 @@ [Latest]

+

Showing releases [% (page - 1) * resultsPerPage + 1 %] - [% (page - 1) * resultsPerPage + releases.size %] out of [% totalReleases %].

+ @@ -62,4 +64,12 @@
+[% IF page > 1 %] + [Prev] +[% END %] +[% IF page * resultsPerPage < totalReleases %] + [Next] +[% END %] +[Last] + [% END %]