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 <david@davidnind.com>
Signed-off-by: Aleisha Amohia <aleisha@catalyst.net.nz>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Kyle M Hall 2026-05-28 10:52:05 -04:00 committed by Pedro Amorim
parent eb57856091
commit 69d9cc4e59
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 10 additions and 6 deletions

View File

@ -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;