From 9409d20f3965150b968cc93592fda6c56827a9d1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 9 Feb 2010 14:08:45 +0000 Subject: [PATCH] * Make the "all" page faster by not doing four identical `select count(*) ...' queries. The reason for this is that my $nrBuilds = scalar($c->stash->{allBuilds}->search({finished => 1})); doesn't return an integer, but some magical code reference that when evaluated performs the query and returns an integer. So every use of $nrBuilds in all.tt caused another query. OTOH using ...->count causes only one query. However count(*) still involves a full table scan, so it's still suboptimal. --- src/lib/Hydra/Base/Controller/ListBuilds.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/Hydra/Base/Controller/ListBuilds.pm b/src/lib/Hydra/Base/Controller/ListBuilds.pm index 85f1e509..e0aae5ab 100644 --- a/src/lib/Hydra/Base/Controller/ListBuilds.pm +++ b/src/lib/Hydra/Base/Controller/ListBuilds.pm @@ -49,13 +49,11 @@ sub errors : Chained('get_builds') PathPart Args(0) { sub all : Chained('get_builds') PathPart { my ($self, $c) = @_; - $c->stash->{template} = 'all.tt'; - my $page = int($c->req->param('page')) || 1; my $resultsPerPage = 20; - my $nrBuilds = scalar($c->stash->{allBuilds}->search({finished => 1})); + my $nrBuilds = $c->stash->{allBuilds}->search({finished => 1})->count; $c->stash->{baseUri} = $c->uri_for($self->action_for("all"), $c->req->captures);