Bugzilla – Attachment 161480 Details for
Bug 35165
Batch item deletions are run in a single transaction and cause locking issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35165: Do not delete items in a transaction
Bug-35165-Do-not-delete-items-in-a-transaction.patch (text/plain), 7.71 KB, created by
Marcel de Rooy
on 2024-01-26 07:52:50 UTC
(
hide
)
Description:
Bug 35165: Do not delete items in a transaction
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2024-01-26 07:52:50 UTC
Size:
7.71 KB
patch
obsolete
>From 812f51bae5d55a5580f15c85cd7bf7c4e090af5a Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 19 Jan 2024 19:06:28 +0000 >Subject: [PATCH] Bug 35165: Do not delete items in a transaction >Content-Type: text/plain; charset=utf-8 > >We are testing the deletion with safe_delete before removing, beyond that I think the intent >was to delete all of the items, deleting some is better than not deleting any. > >To test: >1 - Apply patch, restart all >2 - Submit a batch deletion >3 - Confirm items are deleted > >Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org> >--- > Koha/BackgroundJob/BatchDeleteItem.pm | 144 ++++++++++++-------------- > 1 file changed, 66 insertions(+), 78 deletions(-) > >diff --git a/Koha/BackgroundJob/BatchDeleteItem.pm b/Koha/BackgroundJob/BatchDeleteItem.pm >index 474450e57b..169fd8545b 100644 >--- a/Koha/BackgroundJob/BatchDeleteItem.pm >+++ b/Koha/BackgroundJob/BatchDeleteItem.pm >@@ -94,101 +94,89 @@ sub process { > @deleted_biblionumbers ); > > try { >- my $schema = Koha::Database->new->schema; >- $schema->txn_do( >- sub { >- my (@biblionumbers); >- for my $record_id ( sort { $a <=> $b } @record_ids ) { >- >- last if $self->get_from_storage->status eq 'cancelled'; >- >- my $item = Koha::Items->find($record_id) || next; >- >- my $return = $item->safe_delete({ skip_record_index => 1, skip_holds_queue => 1 }); >- unless ( $return ) { >- >- # FIXME Do we need to rollback the whole transaction if a deletion failed? >- push @not_deleted_itemnumbers, $item->itemnumber; >- push @messages, >- { >- type => 'error', >- code => 'item_not_deleted', >- itemnumber => $item->itemnumber, >- biblionumber => $item->biblionumber, >- barcode => $item->barcode, >- title => $item->biblio->title, >- reason => @{$return->messages}[0]->message, >- }; >- >- next; >- } >- >- push @deleted_itemnumbers, $item->itemnumber; >- push @biblionumbers, $item->biblionumber; >- >- $report->{total_success}++; >- $self->step; >- } >+ my (@biblionumbers); >+ for my $record_id ( sort { $a <=> $b } @record_ids ) { > >- # If there are no items left, delete the biblio >- my @updated_biblionumbers; >- for my $biblionumber ( uniq @biblionumbers ) { >- my $items_count = >- Koha::Biblios->find($biblionumber)->items->count; >- if ( $delete_biblios && $items_count == 0 ) { >- my $error = C4::Biblio::DelBiblio( $biblionumber, >- { skip_record_index => 1, skip_holds_queue => 1 } ); >- unless ($error) { >- push @deleted_biblionumbers, $biblionumber; >- } >- } else { >- push @updated_biblionumbers, $biblionumber; >- } >- } >+ last if $self->get_from_storage->status eq 'cancelled'; > >- if (@deleted_biblionumbers) { >- my $indexer = Koha::SearchEngine::Indexer->new( >- { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); >+ my $item = Koha::Items->find($record_id) || next; > >- $indexer->index_records( \@deleted_biblionumbers, >- 'recordDelete', "biblioserver", undef ); >+ my $return = $item->safe_delete( { skip_record_index => 1, skip_holds_queue => 1 } ); >+ unless ($return) { > >- Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >- { >- biblio_ids => \@deleted_biblionumbers >- } >- ) if C4::Context->preference('RealTimeHoldsQueue'); >- } >+ push @not_deleted_itemnumbers, $item->itemnumber; >+ push @messages, >+ { >+ type => 'error', >+ code => 'item_not_deleted', >+ itemnumber => $item->itemnumber, >+ biblionumber => $item->biblionumber, >+ barcode => $item->barcode, >+ title => $item->biblio->title, >+ reason => @{ $return->messages }[0]->message, >+ }; >+ >+ next; >+ } > >- if (@updated_biblionumbers) { >- my $indexer = Koha::SearchEngine::Indexer->new( >- { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); >+ push @deleted_itemnumbers, $item->itemnumber; >+ push @biblionumbers, $item->biblionumber; > >- $indexer->index_records( \@updated_biblionumbers, >- 'specialUpdate', "biblioserver", undef ); >+ $report->{total_success}++; >+ $self->step; >+ } > >- Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >- { >- biblio_ids => \@updated_biblionumbers >- } >- ) if C4::Context->preference('RealTimeHoldsQueue'); >+ # If there are no items left, delete the biblio >+ my @updated_biblionumbers; >+ for my $biblionumber ( uniq @biblionumbers ) { >+ my $items_count = Koha::Biblios->find($biblionumber)->items->count; >+ if ( $delete_biblios && $items_count == 0 ) { >+ my $error = C4::Biblio::DelBiblio( >+ $biblionumber, >+ { skip_record_index => 1, skip_holds_queue => 1 } >+ ); >+ unless ($error) { >+ push @deleted_biblionumbers, $biblionumber; > } >+ } else { >+ push @updated_biblionumbers, $biblionumber; > } >- ); >- } >- catch { >+ } >+ >+ if (@deleted_biblionumbers) { >+ my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); >+ >+ $indexer->index_records( >+ \@deleted_biblionumbers, >+ 'recordDelete', "biblioserver", undef >+ ); >+ >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@deleted_biblionumbers } ) >+ if C4::Context->preference('RealTimeHoldsQueue'); >+ } >+ >+ if (@updated_biblionumbers) { >+ my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); >+ >+ $indexer->index_records( >+ \@updated_biblionumbers, >+ 'specialUpdate', "biblioserver", undef >+ ); >+ >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@updated_biblionumbers } ) >+ if C4::Context->preference('RealTimeHoldsQueue'); >+ } >+ } catch { > > warn $_; > > push @messages, >- { >+ { > type => 'error', > code => 'unknown', > error => $_, >- }; >+ }; > >- die "Something terrible has happened!" >- if ( $_ =~ /Rollback failed/ ); # Rollback failed > }; > > $report->{deleted_itemnumbers} = \@deleted_itemnumbers; >-- >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 35165
:
161219
|
161220
|
161368
|
161369
|
161370
| 161480