Bug 24683: Optimize loop in ItemsAnyAvailableAndNotRestricted
[koha.git] / C4 / Reserves.pm
index 9d88339..ee1a169 100644 (file)
@@ -1325,8 +1325,6 @@ sub ItemsAnyAvailableAndNotRestricted {
 
     my @items = Koha::Items->search( { biblionumber => $param->{biblionumber} } );
 
-    my $any_available = 0;
-
     foreach my $i (@items) {
         my $reserves_control_branch =
             GetReservesControlBranch( $i->unblessed(), $param->{patron}->unblessed );
@@ -1334,7 +1332,8 @@ sub ItemsAnyAvailableAndNotRestricted {
             C4::Circulation::GetBranchItemRule( $reserves_control_branch, $i->itype );
         my $item_library = Koha::Libraries->find( { branchcode => $i->homebranch } );
 
-        $any_available = 1
+        # we can return (end the loop) when first one found:
+        return 1
             unless $i->itemlost
             || $i->notforloan > 0
             || $i->withdrawn
@@ -1347,7 +1346,7 @@ sub ItemsAnyAvailableAndNotRestricted {
             || $branchitemrule->{holdallowed} == 3 && ! $item_library->validate_hold_sibling( { branchcode => $param->{patron}->branchcode } );
     }
 
-    return $any_available;
+    return 0;
 }
 
 =head2 AlterPriority