From c6f819840a891e493582026c307797ef7d31c5f0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 4 Aug 2020 12:21:26 +0200 Subject: [PATCH] Bug 26132: Don't prefetch if not needed We only need to prefetch items if CircControl is set to ItemHomeLibrary Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 57c03d8e8f..60c417141f 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -432,14 +432,17 @@ sub TooMany { # rule if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "") { - my $checkouts = $patron->checkouts->search( {}, { prefetch => 'item' } ); + my $checkouts; if ( $maxissueqty_rule->branchcode ) { if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { - $checkouts = $checkouts->search({ 'me.branchcode' => $maxissueqty_rule->branchcode }); + $checkouts = $patron->checkouts->search( + { 'me.branchcode' => $maxissueqty_rule->branchcode } ); } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { ; # if branch is the patron's home branch, then count all loans by patron } else { - $checkouts = $checkouts->search({ 'item.homebranch' => $maxissueqty_rule->branchcode }); + $checkouts = $patron->checkouts->search( + { 'item.homebranch' => $maxissueqty_rule->branchcode }, + { prefetch => 'item' } ); } } my $sum_checkouts; @@ -516,13 +519,15 @@ sub TooMany { # Now count total loans against the limit for the branch my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') { - my $checkouts = $patron->checkouts->search({}, { prefetch => 'item' }); + my $checkouts; if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { - $checkouts = $checkouts->search({ 'me.branchcode' => $branch }); + $checkouts = $patron->checkouts->search( + { 'me.branchcode' => $branch} ); } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { ; # if branch is the patron's home branch, then count all loans by patron } else { - $checkouts = $checkouts->search({ 'item.homebranch' => $branch }); + $checkouts = $patron->checkouts->search( + { 'item.homebranch' => $branch} ); } my $checkout_count = $checkouts->count; -- 2.39.5