From fe1dbf07bd96d2c40757f1cacf068c0420ba8b97 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 5 May 2023 13:45:59 -0400 Subject: [PATCH] Bug 33691: Improve query for do_check_for_previous_checkout do_check_for_previous_checkout will pass a list of itemnumbers as part of the query. This could be hundreds of items or more. It makes sense to check by biblionumber instead when possible. Test Plan: 1) prove t/db_dependent/Patron/Borrower_PrevCheckout.t 2) Apply this patch 3) prove t/db_dependent/Patron/Borrower_PrevCheckout.t 4) Test still pass! Signed-off-by: David Nind --- Koha/Patron.pm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index f0e1734217..2b5f8dd638 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -726,21 +726,21 @@ $PATRON, 0 otherwise. sub do_check_for_previous_checkout { my ( $self, $item ) = @_; + my $criteria = { borrowernumber => $self->borrowernumber }; + my $attrs = {}; + my @item_nos; my $biblio = Koha::Biblios->find( $item->{biblionumber} ); + # Create (old)issues search criteria if ( $biblio->is_serial ) { - push @item_nos, $item->{itemnumber}; + $criteria->{itemnumber} = $item->{itemnumber}; } else { # Get all itemnumbers for given bibliographic record. @item_nos = $biblio->items->get_column( 'itemnumber' ); + $criteria->{'biblio.biblionumber'} = $item->{biblionumber}; + $attrs->{join} = { 'item' => 'biblio' }; } - # Create (old)issues search criteria - my $criteria = { - borrowernumber => $self->borrowernumber, - itemnumber => \@item_nos, - }; - my $delay = C4::Context->preference('CheckPrevCheckoutDelay') || 0; if ($delay) { my $dtf = Koha::Database->new->schema->storage->datetime_parser; @@ -749,12 +749,11 @@ sub do_check_for_previous_checkout { } # Check current issues table - my $issues = Koha::Checkouts->search($criteria); - return 1 if $issues->count; # 0 || N + return 1 + if Koha::Checkouts->search( $criteria, $attrs )->count; # Check old issues table - my $old_issues = Koha::Old::Checkouts->search($criteria); - return $old_issues->count; # 0 || N + return Koha::Old::Checkouts->search( $criteria, $attrs )->count; } =head3 is_debarred -- 2.30.2