From cc4f879465d19e9ac761809497281f8b88145ac5 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 30 Nov 2023 12:10:41 -0500 Subject: [PATCH] Bug 35438: Transact each record import separately When importing a staged file we commit every 50 records For an authority import we are also merging, which can affect many more biblios, and these all end up in the transaction. This can cause tables locks and issues across Koha Test Plan: 1) Apply this patch 2) prove t/db_dependent/ImportBatch.t Signed-off-by: David Nind Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer (cherry picked from commit 74bbb89e9941aab7bf3f946d663d0d66b9df4021) Signed-off-by: Fridolin Somers --- C4/ImportBatch.pm | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 00fd7f3d43..2fb22c64fd 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -538,9 +538,6 @@ sub BatchCommitRecords { $progress_interval = 0 unless ref($progress_callback) eq 'CODE'; my $schema = Koha::Database->schema; - $schema->txn_begin; - # NOTE: Moved this transaction to the front of the routine. Note that inside the while loop below - # transactions may be committed and started too again. The final commit is close to the end. my $record_type; my $num_added = 0; @@ -571,15 +568,14 @@ sub BatchCommitRecords { my @biblio_ids; my @updated_ids; while (my $rowref = $sth->fetchrow_hashref) { + $schema->txn_begin; $record_type = $rowref->{'record_type'}; $rec_num++; if ($progress_interval and (0 == ($rec_num % $progress_interval))) { - # report progress and commit - $schema->txn_commit unless $skip_intermediate_commit; + # report progress &$progress_callback( $rec_num ); - $schema->txn_begin unless $skip_intermediate_commit; } if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') { $num_ignored++; @@ -708,6 +704,7 @@ sub BatchCommitRecords { } SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored'); } + $schema->txn_commit; } if ($progress_interval){ @@ -718,8 +715,6 @@ sub BatchCommitRecords { SetImportBatchStatus($batch_id, 'imported'); - # final commit should be before Elastic background indexing in order to find job data - $schema->txn_commit; if (@biblio_ids) { my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); -- 2.39.5