From 68f54437a3e5050474d007434b2acc13bc3494ce Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 16 Mar 2021 10:12:39 +0000 Subject: [PATCH] Bug 24295: Remove GetTransfers call from C4/HoldsQueue.pm MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch removes the GetTransfers call from GetItemsAvailableToFillHoldRequestsForBib instead replacing it with an inline JOIN in the initial query. Test plan 1/ Run the holds queue 2/ Check the results 3/ Put one of the items in the holds queue into transit 4/ Run the holds queue again 5/ Check that the results do not contain the item that is in transit 6/ Apply the patch 7/ Run the holds queue again 8/ Check that the results still do not contain the item that is in transit Rebased-by: Joonas Kylmälä Signed-off-by: Joonas Kylmälä Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- C4/HoldsQueue.pm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index f2eb1ee4b8..8173efaae8 100644 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -23,7 +23,7 @@ use strict; use warnings; use C4::Context; -use C4::Circulation qw( GetTransfers GetBranchItemRule ); +use C4::Circulation qw( GetBranchItemRule ); use Koha::DateUtils qw( dt_from_string ); use Koha::Items; use Koha::Patrons; @@ -314,7 +314,7 @@ sub GetItemsAvailableToFillHoldRequestsForBib { my ($biblionumber, $branches_to_use) = @_; my $dbh = C4::Context->dbh; - my $items_query = "SELECT itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype + my $items_query = "SELECT items.itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype FROM items "; if (C4::Context->preference('item-level_itypes')) { @@ -323,14 +323,17 @@ sub GetItemsAvailableToFillHoldRequestsForBib { $items_query .= "JOIN biblioitems USING (biblioitemnumber) LEFT JOIN itemtypes USING (itemtype) "; } - $items_query .= "WHERE items.notforloan = 0 + $items_query .= " LEFT JOIN branchtransfers ON (items.itemnumber = branchtransfers.itemnumber)"; + $items_query .= " WHERE items.notforloan = 0 AND holdingbranch IS NOT NULL AND itemlost = 0 AND withdrawn = 0"; + $items_query .= " AND branchtransfers.datearrived IS NULL + AND branchtransfers.datecancelled IS NULL"; $items_query .= " AND damaged = 0" unless C4::Context->preference('AllowHoldsOnDamagedItems'); $items_query .= " AND items.onloan IS NULL AND (itemtypes.notforloan IS NULL OR itemtypes.notforloan = 0) - AND itemnumber NOT IN ( + AND items.itemnumber NOT IN ( SELECT itemnumber FROM reserves WHERE biblionumber = ? @@ -348,12 +351,11 @@ sub GetItemsAvailableToFillHoldRequestsForBib { $sth->execute(@params); my $itm = $sth->fetchall_arrayref({}); - my @items = grep { ! scalar C4::Circulation::GetTransfers($_->{itemnumber}) } @$itm; return [ grep { my $rule = C4::Circulation::GetBranchItemRule($_->{homebranch}, $_->{itype}); $_->{holdallowed} = $rule->{holdallowed}; $_->{hold_fulfillment_policy} = $rule->{hold_fulfillment_policy}; - } @items ]; + } @{$itm} ]; } =head2 _checkHoldPolicy -- 2.39.5