From aa7bffc1a3f2fa3b75b0cb5b089dc9dfa713624d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 11 Feb 2022 19:39:33 +0000 Subject: [PATCH] Bug 30085: Don't fetch ReservesControlBranch twice We essentially copy the code from GetReservesControlBranch here, because we also calculate 'branchfield' Setting it to "" vs undef makes no difference in this code, so lets not fetch this again later. Rename the variable to make it clearer where the branchcode came from Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Fridolin Somers --- C4/Reserves.pm | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 38a6ddd41f..2f8fb579aa 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -421,16 +421,16 @@ sub CanItemBeReserved { WHERE borrowernumber = ? }; - my $branchcode = ""; + my $reserves_control_branch; my $branchfield = "reserves.branchcode"; if ( $controlbranch eq "ItemHomeLibrary" ) { $branchfield = "items.homebranch"; - $branchcode = $item->homebranch; + $reserves_control_branch = $item->homebranch; } elsif ( $controlbranch eq "PatronLibrary" ) { $branchfield = "borrowers.branchcode"; - $branchcode = $borrower->{branchcode}; + $reserves_control_branch = $borrower->{branchcode}; } # we retrieve rights @@ -438,7 +438,7 @@ sub CanItemBeReserved { my $reservesallowed = Koha::CirculationRules->get_effective_rule({ itemtype => $item->effective_itemtype, categorycode => $borrower->{categorycode}, - branchcode => $branchcode, + branchcode => $reserves_control_branch, rule_name => 'reservesallowed', }) ) { @@ -452,7 +452,7 @@ sub CanItemBeReserved { my $rights = Koha::CirculationRules->get_effective_rules({ categorycode => $borrower->{'categorycode'}, itemtype => $item->effective_itemtype, - branchcode => $branchcode, + branchcode => $reserves_control_branch, rules => ['holds_per_record','holds_per_day'] }); my $holds_per_record = $rights->{holds_per_record} // 1; @@ -497,10 +497,10 @@ sub CanItemBeReserved { my $sthcount = $dbh->prepare($querycount); if ( defined $ruleitemtype ) { - $sthcount->execute( $patron->borrowernumber, $branchcode, $ruleitemtype ); + $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype ); } else { - $sthcount->execute( $patron->borrowernumber, $branchcode ); + $sthcount->execute( $patron->borrowernumber, $reserves_control_branch ); } my $reservecount = "0"; @@ -522,7 +522,7 @@ sub CanItemBeReserved { my $rule = Koha::CirculationRules->get_effective_rule( { categorycode => $patron->categorycode, - branchcode => $branchcode, + branchcode => $reserves_control_branch, rule_name => 'max_holds', } ); @@ -536,8 +536,6 @@ sub CanItemBeReserved { return { status => 'tooManyReserves', limit => $rule->rule_value} if $total_holds_count >= $rule->rule_value; } - my $reserves_control_branch = - GetReservesControlBranch( $item->unblessed(), $patron->unblessed ); my $branchitemrule = C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->effective_itemtype ); -- 2.39.2