Optimize away always-true hold count clause
[Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / Application / Circ / Holds.pm
index 1df7239..cb99b3d 100644 (file)
@@ -3046,10 +3046,10 @@ sub find_nearest_permitted_hold {
     $copy->call_number($editor->retrieve_asset_call_number($copy->call_number))
         unless ref $copy->call_number;
 
-       # search for what should be the best holds for this copy to fulfill
-       my $best_holds = $U->storagereq(
+    # search for what should be the best holds for this copy to fulfill
+    my $best_holds = $U->storagereq(
         "open-ils.storage.action.hold_request.nearest_hold.atomic", 
-               $user->ws_ou, $copy, 100, $hold_stall_interval, $fifo );
+        $user->ws_ou, $copy, 100, $hold_stall_interval, $fifo );
 
     # Add any pre-targeted holds to the list too? Unless they are already there, anyway.
     if ($old_holds) {
@@ -4133,6 +4133,11 @@ sub rec_hold_count {
 
 
     if (my $pld = $args->{pickup_lib_descendant}) {
+
+        my $top_ou = new_editor()->search_actor_org_unit(
+            {parent_ou => undef}
+        )->[0]; # XXX Assumes single root node. Not alone in this...
+
         $query->{where}->{'+ahr'}->{pickup_lib} = {
             in => {
                 select  => {aou => [{ 
@@ -4143,7 +4148,7 @@ sub rec_hold_count {
                 from    => 'aou',
                 where   => {id => $pld}
             }
-        };
+        } if ($pld != $top_ou->id);
     }