From 0783858a601f14da67f2aff87da25bd7f3fd2990 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 | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 957d40b991..9033032366 100644 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -452,18 +452,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 _can_item_fill_request( $item, $request, $libraries ); - - next if $request->{itemnumber} && $request->{itemnumber} != $item->{itemnumber}; my $local_holds_priority_item_branchcode = $item->{$LocalHoldsPriorityItemControl}; @@ -480,6 +474,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 _can_item_fill_request( $item, $request, $libraries ); + + 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