From ca7c8f3ca46d6dce541acd0f903581fd76aecf07 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Tue, 23 Jan 2024 10:09:05 +0100 Subject: [PATCH] Bug 35899: don't perform expensive checks on non-local items when examining local items --- C4/HoldsQueue.pm | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 5e555f4f95..e554b1257e 100644 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -434,22 +434,12 @@ sub MapItemsToHoldRequests { my $LocalHoldsPriorityItemControl = C4::Context->preference('LocalHoldsPriorityItemControl'); + REQUEST: foreach my $request (@$hold_requests) { + my $patron; last if $num_items_remaining == 0; - my $patron = Koha::Patrons->find($request->{borrowernumber}); - next if $patron->category->exclude_from_local_holds_priority; - my $local_hold_match; foreach my $item (@$available_items) { - next if $item->{_object}->exclude_from_local_holds_priority; - - next unless _checkHoldPolicy($item, $request); - - next if $request->{itemnumber} && $request->{itemnumber} != $item->{itemnumber}; - - next if $request->{item_group_id} && $item->{_object}->item_group && $item->{_object}->item_group->id ne $request->{item_group_id}; - - next unless $item->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); my $local_holds_priority_item_branchcode = $item->{$LocalHoldsPriorityItemControl}; @@ -466,6 +456,26 @@ sub MapItemsToHoldRequests { $local_holds_priority_patron_branchcode; if ($local_hold_match) { + next if $item->{_object}->exclude_from_local_holds_priority; + + if ( !defined $patron ) { + $patron = Koha::Patrons->find( $request->{borrowernumber} ); + + next REQUEST if $patron->category->exclude_from_local_holds_priority; + } + + next unless _checkHoldPolicy( $item, $request ); + + next if $request->{itemnumber} && $request->{itemnumber} != $item->{itemnumber}; + + next + if $request->{item_group_id} + && $item->{_object}->item_group + && $item->{_object}->item_group->id ne $request->{item_group_id}; + + next + unless $item->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } ); + if ( exists $items_by_itemnumber{ $item->{itemnumber} } and not exists $allocated_items{ $item->{itemnumber} } and not $request->{allocated}) -- 2.39.2