From d5cffd4bc7fc05bbd7051dc3413ba611d6c0abbf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 16 Mar 2016 15:19:18 +0100 Subject: [PATCH] Make "Running builds" and "Machine status" pages faster --- src/lib/Hydra/Controller/Root.pm | 16 ++++++++-------- src/lib/Hydra/Helper/CatalystUtils.pm | 7 +++++++ src/root/machine-status.tt | 6 +++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 722de6e4..5109b3b8 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -45,7 +45,7 @@ sub begin :Private { } if (scalar(@args) == 0 || $args[0] ne "static") { - $c->stash->{nrRunningBuilds} = $c->model('DB')->schema->storage->dbh->selectrow_array( + $c->stash->{nrRunningBuilds} = dbh($c)->selectrow_array( "select count(distinct build) from buildsteps where busy = 1"); $c->stash->{nrQueuedBuilds} = $c->model('DB::Builds')->search({ finished => 0 })->count(); } @@ -105,7 +105,7 @@ sub queue_summary :Local :Path('queue-summary') :Args(0) { my ($self, $c) = @_; $c->stash->{template} = 'queue-summary.tt'; - $c->stash->{queued} = $c->model('DB')->schema->storage->dbh->selectall_arrayref( + $c->stash->{queued} = dbh($c)->selectall_arrayref( "select project, jobset, count(*) as queued, min(timestamp) as oldest, max(timestamp) as newest from Builds " . "where finished = 0 group by project, jobset order by queued desc", { Slice => {} }); @@ -119,7 +119,7 @@ sub status_GET { $self->status_ok( $c, entity => [$c->model('DB::Builds')->search( - { finished => 0, "buildsteps.busy" => 1 }, + { "buildsteps.busy" => 1 }, { order_by => ["globalpriority DESC", "id"], join => "buildsteps", columns => [@buildListColumns] @@ -164,11 +164,11 @@ sub machines :Local Args(0) { } $c->stash->{machines} = $machines; - $c->stash->{steps} = [ $c->model('DB::BuildSteps')->search( - { finished => 0, 'me.busy' => 1, }, - { join => [ 'build' ] - , order_by => [ 'machine', 'stepnr' ] - } ) ]; + $c->stash->{steps} = dbh($c)->selectall_arrayref( + "select build, stepnr, s.system as system, s.drvpath as drvpath, machine, s.starttime as starttime, project, jobset, job " . + "from BuildSteps s join Builds b on s.build = b.id " . + "where busy = 1 order by machine, stepnr", + { Slice => {} }); $c->stash->{template} = 'machine-status.tt'; } diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 6f05e8e5..df966d80 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -26,6 +26,7 @@ our @EXPORT = qw( setCacheHeaders approxTableSize requireLocalStore + dbh ); @@ -351,4 +352,10 @@ sub requireLocalStore { } +sub dbh { + my ($c) = @_; + return $c->model('DB')->schema->storage->dbh; +} + + 1; diff --git a/src/root/machine-status.tt b/src/root/machine-status.tt index 8473d0b9..5f406ae1 100644 --- a/src/root/machine-status.tt +++ b/src/root/machine-status.tt @@ -39,10 +39,10 @@ [% IF name == name2 %] [% idle = 0 %] - [% INCLUDE renderFullJobNameOfBuild build=step.build %] + [% INCLUDE renderFullJobName project=step.project jobset=step.jobset job=step.job %] [% step.system %] - [% step.build.id %] - [% step.stepnr %] + [% step.build %] + [% step.stepnr %] [% step.drvpath.match('-(.*)').0 %] [% INCLUDE renderDuration duration = curTime - step.starttime %]