* 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.
This commit is contained in:
Eelco Dolstra 2010-02-09 14:08:45 +00:00
parent 59e4f65298
commit 9409d20f39

View file

@ -49,13 +49,11 @@ sub errors : Chained('get_builds') PathPart Args(0) {
sub all : Chained('get_builds') PathPart { sub all : Chained('get_builds') PathPart {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->stash->{template} = 'all.tt';
my $page = int($c->req->param('page')) || 1; my $page = int($c->req->param('page')) || 1;
my $resultsPerPage = 20; 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); $c->stash->{baseUri} = $c->uri_for($self->action_for("all"), $c->req->captures);