From 78b7094b8d96f36d57ee4ce53254af4683074dae Mon Sep 17 00:00:00 2001 From: Andrew Nugged Date: Sat, 7 Dec 2019 14:37:58 +0200 Subject: [PATCH] Bug 24185: Make holds page faster - improved "if" `$can_item_be_reserved eq 'OK'` moved in `&&` before `IsAvailableForItemLevelRequest` to cut away with static known values before calling to more resource consuming subroutine. --- C4/Reserves.pm | 17 ++++++++++++++--- reserve/request.pl | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 7a3785724a..ed9f47c1b6 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1188,7 +1188,12 @@ and canreservefromotherbranches. =cut sub IsAvailableForItemLevelRequest { - my ( $item, $patron, $pickup_branchcode ) = @_; + my $item = shift; + my $patron = shift; + my $pickup_branchcode = shift; + # items_any_available is precalculated status passed from request.pl when set of items + # looped outside of IsAvailableForItemLevelRequest to avoid nested loops: + my $items_any_available = shift; my $dbh = C4::Context->dbh; # must check the notforloan setting of the itemtype @@ -1205,8 +1210,6 @@ sub IsAvailableForItemLevelRequest { $item->withdrawn || ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems')); - my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); - if ($pickup_branchcode) { my $destination = Koha::Libraries->find($pickup_branchcode); return 0 unless $destination; @@ -1214,9 +1217,17 @@ sub IsAvailableForItemLevelRequest { return 0 unless $item->can_be_transferred( { to => $destination } ); } + my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } ); + if ( $on_shelf_holds == 1 ) { return 1; } elsif ( $on_shelf_holds == 2 ) { + + # if we have this param predefined from outer caller sub, we just need + # to return it, so we saving from having loop inside other loop: + return $items_any_available ? 0 : 1 + if defined $items_any_available; + my @items = Koha::Items->search( { biblionumber => $item->biblionumber } ); diff --git a/reserve/request.pl b/reserve/request.pl index 4f80b8d5b9..dc345900dc 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -556,8 +556,8 @@ foreach my $biblionumber (@biblionumbers) { if ( !$item->{cantreserve} && !$exceeded_maxreserves - && IsAvailableForItemLevelRequest($item_object, $patron) && $can_item_be_reserved eq 'OK' + && IsAvailableForItemLevelRequest($item_object, $patron) ) { $item->{available} = 1; -- 2.17.1