Commit 4f82c413 authored by Gary Wong's avatar Gary Wong

Replace 20 lines of buggy Perl with a single (less buggy?) SQL query.

parent 937c6efa
......@@ -965,32 +965,22 @@ sub CurrentReservations($$) {
# reject illegal PIDs
return undef unless /^[-\w]+$/;
}
my $query_result = DBQueryFatal( "SELECT DISTINCT(type) FROM " .
"future_reservations WHERE pid IN ('" .
join( "','", @$projlist ) . "')" );
while( my($type) = $query_result->fetchrow_array() ) {
my $reservations = LookupAll( $class, $type );
my @forecast = ();
IsFeasible( $class, $reservations, undef, undef, undef, undef,
\@forecast );
my $query_result = DBQueryFatal(
"SELECT q.*, COUNT(*) AS used FROM (" .
"SELECT pid, type, SUM( nodes ) AS reserved FROM " .
"future_reservations WHERE start <= NOW() AND end > NOW() " .
"GROUP BY pid, type) AS q ".
"LEFT OUTER JOIN reserved AS r ON q.pid=r.pid " .
"INNER JOIN nodes AS n ON r.node_id=n.node_id WHERE " .
"n.type=q.type GROUP BY q.pid, q.type" );
foreach my $f ( @forecast ) {
foreach my $pid ( keys ( %{$f->{'reserved'}} ) ) {
if( grep( $_ eq $pid, @$projlist ) ) {
last if( $f->{'t'} > time );
push( @answer, { 'pid' => $pid, 'nodetype' => $type,
'reserved' => $f->{'reserved'}->{$pid},
'used' => $f->{'used'}->{$pid} } );
}
}
}
while( my($pid, $type, $reserved, $used) =
$query_result->fetchrow_array() ) {
push( @answer, { 'pid' => $pid, 'nodetype' => $type,
'reserved' => $reserved, 'used' => $used } );
}
return @answer;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment