Bugzilla – Attachment 157971 Details for
Bug 34678
Concurrent changes to the holds can fail due to primary key constraints
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34678: Allow new entries to overwrite hold_fill_targets
Bug-34678-Allow-new-entries-to-overwrite-holdfillt.patch (text/plain), 2.82 KB, created by
Marcel de Rooy
on 2023-10-27 06:45:19 UTC
(
hide
)
Description:
Bug 34678: Allow new entries to overwrite hold_fill_targets
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-10-27 06:45:19 UTC
Size:
2.82 KB
patch
obsolete
>From 4f125380cdb11b99630d9665fa889050971c4ac9 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 13 Sep 2023 17:03:32 +0000 >Subject: [PATCH] Bug 34678: Allow new entries to overwrite hold_fill_targets >Content-Type: text/plain; charset=utf-8 > >When using background jobs, there is a possibility of a race condition where two jobs will be updating the holds queue for the same biblio. We should try to minimize those cases (see bug 34596) > >In the meantime though, we should prevent jobs possibly dying, and allow the most recent update to succeed. > >There is a possibility two updates wil assign different items to the same reserve, and that a reserve could end up in the queue twice, however, whichever one is filled first will delete both entries. as filling the hold deletes by reserve id (see bug 24359) > >This patch adds a transaction to delete and then inset the new row > >To test: >1 - prove -v t/db_dependent/Reserves.t >2 - It fails >3 - Apply patch >4 - t/db_dependent/Reserves.t >5 - It succeeds! > >Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > C4/HoldsQueue.pm | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) > >diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm >index 4b811627eb..5e555f4f95 100644 >--- a/C4/HoldsQueue.pm >+++ b/C4/HoldsQueue.pm >@@ -773,18 +773,25 @@ sub CreatePicklistFromItemMap { > sub AddToHoldTargetMap { > my $item_map = shift; > >- my $dbh = C4::Context->dbh; >+ my $dbh = C4::Context->dbh; >+ my $schema = Koha::Database->new->schema; > > my $insert_sql = q( >- INSERT INTO hold_fill_targets (borrowernumber, biblionumber, itemnumber, source_branchcode, item_level_request, reserve_id) >- VALUES (?, ?, ?, ?, ?, ?) >+ INSERT INTO hold_fill_targets (borrowernumber, biblionumber, itemnumber, source_branchcode, item_level_request, reserve_id) VALUES (?, ?, ?, ?, ?, ?) > ); > my $sth_insert = $dbh->prepare($insert_sql); > >- foreach my $itemnumber (keys %$item_map) { >+ foreach my $itemnumber ( keys %$item_map ) { > my $mapped_item = $item_map->{$itemnumber}; >- $sth_insert->execute($mapped_item->{borrowernumber}, $mapped_item->{biblionumber}, $itemnumber, >- $mapped_item->{holdingbranch}, $mapped_item->{item_level}, $mapped_item->{reserve_id}); >+ $schema->txn_do( >+ sub { >+ $dbh->do( 'DELETE FROM hold_fill_targets WHERE itemnumber = ?', {}, $itemnumber ); >+ $sth_insert->execute( >+ $mapped_item->{borrowernumber}, $mapped_item->{biblionumber}, $itemnumber, >+ $mapped_item->{holdingbranch}, $mapped_item->{item_level}, $mapped_item->{reserve_id} >+ ); >+ } >+ ); > } > } > >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34678
:
155594
|
155595
|
155628
|
155629
|
157913
|
157914
|
157950
|
157951
|
157970
| 157971