From 2e6e0f3db17f94db51835c92bb5d82f705d2df7f Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 28 Sep 2021 12:35:18 -0400 Subject: [PATCH] Bug 29130 - Holds queue is empty while holds queue builder is running When build_holds_queue.pl, it first deletes all rows from tmp_holdsqueue and hold_fill_targets, then starts building the holds queue again. It seems sensible to build the holds queue using temporary tables and copy the data over afterward. Test Plan: 1) Apply this patch 2) Run the holds queue builder 3) Verify holds queue was was populated --- C4/HoldsQueue.pm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 06b0b2a2ef..459ea1be5b 100644 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -175,7 +175,9 @@ Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets sub CreateQueue { my $dbh = C4::Context->dbh; - $dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info + $dbh->do("CREATE TABLE IF NOT EXISTS tmp_holdsqueue_builder LIKE tmp_holdsqueue"); + $dbh->do("DELETE FROM tmp_holdsqueue_builder"); + $dbh->do("CREATE TABLE IF NOT EXISTS hold_fill_targets_builder LIKE hold_fill_targets"); $dbh->do("DELETE FROM hold_fill_targets"); my $total_bibs = 0; @@ -222,6 +224,16 @@ sub CreateQueue { #warn Dumper($hold_requests), Dumper($available_items), Dumper($item_map); } } + + my $do_not_lock = ( exists $ENV{_} && $ENV{_} =~ m|prove| ) || $ENV{KOHA_TESTING}; + $dbh->{AutoCommit} = 0 unless $do_not_lock; + $dbh->do("DELETE FROM tmp_holdsqueue"); # clear the old table for new info + $dbh->do("INSERT INTO tmp_holdsqueue SELECT * FROM tmp_holdsqueue_builder"); + $dbh->do("DELETE FROM hold_fill_targets"); + $dbh->do("INSERT INTO hold_fill_targets SELECT * FROM hold_fill_targets_builder"); + $dbh->do("DROP TABLE tmp_holdsqueue_builder"); + $dbh->do("DROP TABLE hold_fill_targets_builder"); + $dbh->commit() unless $do_not_lock; } =head2 GetBibsWithPendingHoldRequests @@ -711,7 +723,7 @@ sub CreatePicklistFromItemMap { my $dbh = C4::Context->dbh; my $sth_load=$dbh->prepare(" - INSERT INTO tmp_holdsqueue (biblionumber,itemnumber,barcode,surname,firstname,phone,borrowernumber, + INSERT INTO tmp_holdsqueue_builder (biblionumber,itemnumber,barcode,surname,firstname,phone,borrowernumber, cardnumber,reservedate,title, itemcallnumber, holdingbranch,pickbranch,notes, item_level_request) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) @@ -756,7 +768,7 @@ sub AddToHoldTargetMap { my $dbh = C4::Context->dbh; my $insert_sql = q( - INSERT INTO hold_fill_targets (borrowernumber, biblionumber, itemnumber, source_branchcode, item_level_request, reserve_id) + INSERT INTO hold_fill_targets_builder (borrowernumber, biblionumber, itemnumber, source_branchcode, item_level_request, reserve_id) VALUES (?, ?, ?, ?, ?, ?) ); my $sth_insert = $dbh->prepare($insert_sql); -- 2.30.1 (Apple Git-130)