From 7528a9c7e7a923c00fc49ef908c70b2a6a225fbb Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 23 Apr 2013 15:20:24 +0200 Subject: [PATCH] Machine status: Don't show removed machines anymore This requires a sequential scan on the BuildSteps table, which by now takes > 8s. --- src/lib/Hydra/Controller/Root.pm | 16 +++++++++++----- src/root/machine-status.tt | 8 ++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 0370cc8c..3d49072d 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -75,12 +75,18 @@ sub status :Local { sub machines :Local Args(0) { my ($self, $c) = @_; my $machines = getMachines; - my $idles = $c->model('DB::BuildSteps')->search( - { stoptime => { '!=', undef } }, - { select => [ 'machine', { max => 'stoptime', -as => 'max_stoptime' }], group_by => "machine" }); - while (my $idle = $idles->next) { - ${$machines}{$idle->machine}{'idle'} = $idle->get_column('max_stoptime'); + + # Add entry for localhost. + ${$machines}{''} //= {}; + + # Get the last finished build step for each machine. + foreach my $m (keys %{$machines}) { + my $idle = $c->model('DB::BuildSteps')->find( + { machine => "$m", stoptime => { '!=', undef } }, + { order_by => 'stoptime desc', rows => 1 }); + ${$machines}{$m}{'idle'} = $idle ? $idle->stoptime : 0; } + $c->stash->{machines} = $machines; $c->stash->{steps} = [ $c->model('DB::BuildSteps')->search( { finished => 0, 'me.busy' => 1, 'build.busy' => 1, }, diff --git a/src/root/machine-status.tt b/src/root/machine-status.tt index 873944c1..72c0501d 100644 --- a/src/root/machine-status.tt +++ b/src/root/machine-status.tt @@ -7,11 +7,7 @@ - [% IF !m.key || m.value.maxJobs %] - Enabled: - [% ELSE %] - Disabled: - [% END %] [% name %] + [% name %] [% IF m.value.systemTypes %] ([% comma=0; FOREACH system IN m.value.systemTypes %][% IF comma; %], [% ELSE; comma = 1; END %][% system %][% END %]) [% END %] @@ -35,7 +31,7 @@ [% END %] [% IF idle == 1 %] [% IF m.value.idle %] - Idle since [% INCLUDE renderDuration duration = curTime - m.value.idle %] + Idle for [% INCLUDE renderDuration duration = curTime - m.value.idle %] [% ELSE %] Never used [% END %]