From 5e5b3445276b5b6ca59617b72ab2ee0d474c03e9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 23 May 2013 12:18:38 -0400 Subject: [PATCH] Make latest/latest-for more efficient Getting all matching rows from the database is expensive. --- src/lib/Hydra/Base/Controller/ListBuilds.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/Hydra/Base/Controller/ListBuilds.pm b/src/lib/Hydra/Base/Controller/ListBuilds.pm index fe2a9770..dd8dafa9 100644 --- a/src/lib/Hydra/Base/Controller/ListBuilds.pm +++ b/src/lib/Hydra/Base/Controller/ListBuilds.pm @@ -96,8 +96,8 @@ sub nix : Chained('get_builds') PathPart('channel') CaptureArgs(1) { sub latest : Chained('get_builds') PathPart('latest') { my ($self, $c, @rest) = @_; - my ($latest) = $c->stash->{allBuilds}->search( - {finished => 1, buildstatus => 0}, {order_by => ["id DESC"]}); + my $latest = $c->stash->{allBuilds}->find( + { finished => 1, buildstatus => 0 }, { order_by => ["id DESC"], rows => 1 }); notFound($c, "There is no successful build to redirect to.") unless defined $latest; @@ -111,8 +111,8 @@ sub latest_for : Chained('get_builds') PathPart('latest-for') { notFound($c, "You need to specify a platform type in the URL.") unless defined $system; - my ($latest) = $c->stash->{allBuilds}->search( - {finished => 1, buildstatus => 0, system => $system}, {order_by => ["id DESC"]}); + my $latest = $c->stash->{allBuilds}->find( + { finished => 1, buildstatus => 0, system => $system }, { order_by => ["id DESC"], rows => 1 }); notFound($c, "There is no successful build for platform `$system' to redirect to.") unless defined $latest;