Without an index on (machine, stoptime desc), this requires a sequential scan. And adding a whole index for this seems overkill. (Possibly the queue runner could maintain this info more efficiently.)
UFFPFIXSKKIWSUHC6D4YPUZRNZJV2YW5V62L6ZQGMY7B3YNQJ43QC
SQINIEM2EQD4U7MWXKJDTOK6KAMLGCEEVRKL67XYVAJEEWD2FWOQC
RFGPN7U7DOFZMPNLJDTS3IXEYSDN57HUDKI5I54NU4LC376JUR2AC
J5UVLXOK6EDIL5I7VKWH4V2QDS4DPD7FHRK6XBWSXFRQS4JKXFZQC
BZUB3ZSH7ZVUTNQYNQYZOCZQ5UIQKDNBC5BJU3T6ITHZ2CERJJ5AC
HTL6HIBMRGSX2H2H7KB4MC3H6UQ5C752VC3UHC43SRA7V66PQCRQC
V6S6OYIAW3ZCBP6UHUYAZGG4P237WBB6HDG5NQIF3E5YFDTQRA4AC
ZWCTAZGLJZQNTYWTC2XQUKMILJF6JGDL5IND6QNYWK4FIGMLRFXAC
J4R2VCPPXW6QPVIDNXVHFRTDAZAPLAFBBBPIQZLZVPUHFXCO67TAC
# 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;
}
[% IF m.value.idle %]
<tr><td colspan="6">Idle for [% INCLUDE renderDuration duration = curTime - m.value.idle %]</td></tr>
[% ELSE %]
<tr><td colspan="6">Never used</td></tr>
[% END %]
<tr><td colspan="6">Idle</td></tr>