This requires a sequential scan on the BuildSteps table, which by now takes > 8s.
RFGPN7U7DOFZMPNLJDTS3IXEYSDN57HUDKI5I54NU4LC376JUR2AC
BZUB3ZSH7ZVUTNQYNQYZOCZQ5UIQKDNBC5BJU3T6ITHZ2CERJJ5AC
J4R2VCPPXW6QPVIDNXVHFRTDAZAPLAFBBBPIQZLZVPUHFXCO67TAC
HTL6HIBMRGSX2H2H7KB4MC3H6UQ5C752VC3UHC43SRA7V66PQCRQC
J5UVLXOK6EDIL5I7VKWH4V2QDS4DPD7FHRK6XBWSXFRQS4JKXFZQC
V6S6OYIAW3ZCBP6UHUYAZGG4P237WBB6HDG5NQIF3E5YFDTQRA4AC
ZWCTAZGLJZQNTYWTC2XQUKMILJF6JGDL5IND6QNYWK4FIGMLRFXAC
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;