Make "Running builds" and "Machine status" pages faster

This commit is contained in:
Eelco Dolstra 2016-03-16 15:19:18 +01:00
parent 1de5ce7a0e
commit d5cffd4bc7
3 changed files with 18 additions and 11 deletions

View file

@ -45,7 +45,7 @@ sub begin :Private {
} }
if (scalar(@args) == 0 || $args[0] ne "static") { 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"); "select count(distinct build) from buildsteps where busy = 1");
$c->stash->{nrQueuedBuilds} = $c->model('DB::Builds')->search({ finished => 0 })->count(); $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) = @_; my ($self, $c) = @_;
$c->stash->{template} = 'queue-summary.tt'; $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 " . "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", "where finished = 0 group by project, jobset order by queued desc",
{ Slice => {} }); { Slice => {} });
@ -119,7 +119,7 @@ sub status_GET {
$self->status_ok( $self->status_ok(
$c, $c,
entity => [$c->model('DB::Builds')->search( entity => [$c->model('DB::Builds')->search(
{ finished => 0, "buildsteps.busy" => 1 }, { "buildsteps.busy" => 1 },
{ order_by => ["globalpriority DESC", "id"], { order_by => ["globalpriority DESC", "id"],
join => "buildsteps", join => "buildsteps",
columns => [@buildListColumns] columns => [@buildListColumns]
@ -164,11 +164,11 @@ sub machines :Local Args(0) {
} }
$c->stash->{machines} = $machines; $c->stash->{machines} = $machines;
$c->stash->{steps} = [ $c->model('DB::BuildSteps')->search( $c->stash->{steps} = dbh($c)->selectall_arrayref(
{ finished => 0, 'me.busy' => 1, }, "select build, stepnr, s.system as system, s.drvpath as drvpath, machine, s.starttime as starttime, project, jobset, job " .
{ join => [ 'build' ] "from BuildSteps s join Builds b on s.build = b.id " .
, order_by => [ 'machine', 'stepnr' ] "where busy = 1 order by machine, stepnr",
} ) ]; { Slice => {} });
$c->stash->{template} = 'machine-status.tt'; $c->stash->{template} = 'machine-status.tt';
} }

View file

@ -26,6 +26,7 @@ our @EXPORT = qw(
setCacheHeaders setCacheHeaders
approxTableSize approxTableSize
requireLocalStore requireLocalStore
dbh
); );
@ -351,4 +352,10 @@ sub requireLocalStore {
} }
sub dbh {
my ($c) = @_;
return $c->model('DB')->schema->storage->dbh;
}
1; 1;

View file

@ -39,10 +39,10 @@
[% IF name == name2 %] [% IF name == name2 %]
[% idle = 0 %] [% idle = 0 %]
<tr> <tr>
<td><tt>[% INCLUDE renderFullJobNameOfBuild build=step.build %]</tt></td> <td><tt>[% INCLUDE renderFullJobName project=step.project jobset=step.jobset job=step.job %]</tt></td>
<td><tt>[% step.system %]</tt></td> <td><tt>[% step.system %]</tt></td>
<td><a href="[% c.uri_for('/build' step.build.id) %]">[% step.build.id %]</a></td> <td><a href="[% c.uri_for('/build' step.build) %]">[% step.build %]</a></td>
<td><a class="row-link" href="[% c.uri_for('/build' step.build.id 'nixlog' step.stepnr 'tail-reload') %]">[% step.stepnr %]</a></td> <td><a class="row-link" href="[% c.uri_for('/build' step.build 'nixlog' step.stepnr 'tail-reload') %]">[% step.stepnr %]</a></td>
<td><tt>[% step.drvpath.match('-(.*)').0 %]</tt></td> <td><tt>[% step.drvpath.match('-(.*)').0 %]</tt></td>
<td style="width: 10em">[% INCLUDE renderDuration duration = curTime - step.starttime %] </td> <td style="width: 10em">[% INCLUDE renderDuration duration = curTime - step.starttime %] </td>
</tr> </tr>