Bug 9367: Followup: Code optimization: CheckReserves is too often called
authorJonathan Druart <jonathan.druart@biblibre.com>
Mon, 11 Mar 2013 10:33:05 +0000 (11:33 +0100)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Sat, 16 Mar 2013 15:49:43 +0000 (11:49 -0400)
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
C4/Circulation.pm
C4/Reserves.pm

index 0999acf..abd4981 100644 (file)
@@ -2473,18 +2473,17 @@ sub CanBookBeRenewed {
 
     $sthcount->execute( $borrowernumber, $itemnumber );
     if ( my $data1 = $sthcount->fetchrow_hashref ) {
-        
         if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) {
             $renewokay = 1;
         }
         else {
-                       $error="too_many";
-               }
-               
+            $error = "too_many";
+        }
+
         my $resstatus = C4::Reserves::GetReserveStatus($itemnumber);
         if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) {
             $renewokay = 0;
-            $error->{message} = "on_reserve";
+            $error = "on_reserve";
         }
     }
     return ($renewokay,$error);
index ee31ea9..ded88c8 100644 (file)
@@ -735,26 +735,33 @@ sub GetReservesForBranch {
     return (@transreserv);
 }
 
+=head2 GetReserveStatus
+
+  $reservestatus = GetReserveStatus($itemnumber, $biblionumber);
+
+Take an itemnumber or a biblionumber and return the status of the reserve places on it.
+If several reserves exist, the reserve with the lower priority is given.
+
+=cut
+
 sub GetReserveStatus {
     my ($itemnumber, $biblionumber) = @_;
 
     my $dbh = C4::Context->dbh;
 
-    my ($sth, $found, $priority);
+    my ($sth, $found, $priority) = (undef, q{}, 0);
     if ( $itemnumber ) {
         $sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE itemnumber = ? order by priority LIMIT 1");
         $sth->execute($itemnumber);
-        ($found, $priority) = $sth->fetchrow_array;
     }
 
     if ( $biblionumber and not defined $found and not defined $priority ) {
         $sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE biblionumber = ? order by priority LIMIT 1");
         $sth->execute($biblionumber);
-    } else {
-        return;
     }
     ($found, $priority) = $sth->fetchrow_array;
 
+    return unless defined $found;
     return 'Waiting'  if $found eq 'W' and $priority == 0;
     return 'Finished' if $found eq 'F';
     return 'Reserved' if $priority > 0;
@@ -1455,8 +1462,7 @@ sub IsAvailableForItemLevelRequest {
     if (C4::Context->preference('AllowOnShelfHolds')) {
         return $available_per_item;
     } else {
-        my $status = GetReserveStatus($itemnumber);
-        return ($available_per_item and ($item->{onloan} or $status eq "Waiting" or $status = "Reserved"));
+        return ($available_per_item and ($item->{onloan} or GetReserveStatus($itemnumber) eq "Waiting"));
     }
 }