From 69d9cc4e5912b1726d12700e02602d56c2e4c1ef Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 28 May 2026 10:52:05 -0400 Subject: [PATCH] Bug 42700: Avoid duplicate holds query query when building SIP patron object This patch fetches the patron's holds once into a list of Koha::Hold objects and derives both hold_items and unavail_holds from that single fetch. Test Plan: 1) Apply this patch 2) prove t/db_dependent/SIP/ 3) Note all tests pass! Signed-off-by: David Nind Signed-off-by: Aleisha Amohia Signed-off-by: Pedro Amorim --- C4/SIP/ILS/Patron.pm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 68be7f8962..9389cb24b5 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -138,6 +138,10 @@ sub new { my $circ_blocked = ( C4::Context->preference('OverduesBlockCirc') ne "noblock" && defined $flags->{ODUES}->{itemlist} ) ? 1 : 0; + + # Fetch holds once and derive hold_items and unavail_holds from the result + my @holds = $patron->holds->as_list; + { no warnings; # any of these $kp->{fields} being concat'd could be undef %ilspatron = ( @@ -168,7 +172,7 @@ sub new { screen_msg => 'Greetings from Koha. ' . $kp->{opacnote} . $fines_msg, print_line => '', items => [], - hold_items => $patron->holds->unblessed, + hold_items => [ map { $_->unblessed } @holds ], overdue_items => $flags->{ODUES}->{itemlist}, too_many_overdue => $circ_blocked, fine_items => [], @@ -223,7 +227,7 @@ sub new { } # FIXME: populate recall_items - $ilspatron{unavail_holds} = _get_outstanding_holds( $kp->{borrowernumber} ); + $ilspatron{unavail_holds} = _get_outstanding_holds( \@holds ); my $pending_checkouts = $patron->pending_checkouts; my @barcodes; @@ -695,12 +699,12 @@ sub _get_address { } sub _get_outstanding_holds { - my $borrowernumber = shift; + my $holds = shift; - my $patron = Koha::Patrons->find($borrowernumber); - my $holds = $patron->holds->search( { -or => [ { found => undef }, { found => { '!=' => 'W' } } ] } ); my @holds; - while ( my $hold = $holds->next ) { + foreach my $hold ( @{$holds} ) { + next if ( $hold->found // '' ) eq 'W'; + my $item; if ( $hold->itemnumber ) { $item = $hold->item;