From 0981e1d2196b37a16de8deeb95b24104335301bb 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 4) prove t/db_dependent/HoldsQueue.t --- C4/HoldsQueue.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 06b0b2a2ef..917dc1e29e 100644 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -175,8 +175,8 @@ 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("DELETE FROM hold_fill_targets"); + $dbh->do("CREATE TEMPORARY TABLE tmp_holdsqueue_builder LIKE tmp_holdsqueue"); + $dbh->do("CREATE TEMPORARY TABLE hold_fill_targets_builder LIKE hold_fill_targets"); my $total_bibs = 0; my $total_requests = 0; @@ -222,6 +222,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 TEMPORARY TABLE tmp_holdsqueue_builder"); + $dbh->do("DROP TEMPORARY TABLE hold_fill_targets_builder"); + $dbh->commit() unless $do_not_lock; } =head2 GetBibsWithPendingHoldRequests @@ -711,7 +721,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 +766,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)