From 5b1bef45ccc20e190057d986617669454de80983 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 20 May 2022 14:29:58 +0000 Subject: [PATCH] Bug 30824: Improve performance of BatchCommitItems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes two simple changes: - Limit TransformMarcToKoha to the fields we need - Pass forward the biblioitemnumber when adding items to a new biblionumber Profiling with NYTProf I saved ~8-9 seconds importing around 400 bibs/1000 items Reducing calls in item store to use a passed biblionumber was the largest gain. To test: 1 - Import some records and items 2 - Verify values etc., revert 3 - Apply patch 4 - Import again 5 - Verify values etc. same as before Signed-off-by: Martin Renvoize Signed-off-by: Joonas Kylmälä --- C4/ImportBatch.pm | 10 +++++----- C4/Items.pm | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 32b741fd95..e0dd051491 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -649,7 +649,7 @@ sub BatchCommitRecords { ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework); $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead if ($item_result eq 'create_new' || $item_result eq 'replace') { - my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result); + my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result, $biblioitemnumber); $num_items_added += $bib_items_added; $num_items_replaced += $bib_items_replaced; $num_items_errored += $bib_items_errored; @@ -735,12 +735,12 @@ sub BatchCommitRecords { =head2 BatchCommitItems ($num_items_added, $num_items_errored) = - BatchCommitItems($import_record_id, $biblionumber); + BatchCommitItems($import_record_id, $biblionumber, [$action, $biblioitemnumber]); =cut sub BatchCommitItems { - my ( $import_record_id, $biblionumber, $action ) = @_; + my ( $import_record_id, $biblionumber, $action, $biblioitemnumber ) = @_; my $dbh = C4::Context->dbh; @@ -765,7 +765,7 @@ sub BatchCommitItems { my ( $MARCfield, $MARCsubfield ) = GetMarcFromKohaField( 'items.onloan' ); $item_marc->field($MARCfield)->delete_subfield( code => $MARCsubfield ); - my $item = TransformMarcToKoha({ record => $item_marc }); + my $item = TransformMarcToKoha({ record => $item_marc, kohafields => ['items.barcode','items.itemnumber'] }); my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} }); my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); @@ -800,7 +800,7 @@ sub BatchCommitItems { my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); - my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber ); + my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, {biblioitemnumber => $biblioitemnumber} ); if( $itemnumber ) { $updsth->bind_param( 1, 'imported' ); $updsth->bind_param( 2, $itemnumber ); diff --git a/C4/Items.pm b/C4/Items.pm index 03305eba33..d358675513 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -162,7 +162,6 @@ sub AddItemFromMarc { # parse item hash from MARC my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber); my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" ); - my $localitemmarc = MARC::Record->new; $localitemmarc->append_fields( $source_item_marc->field($itemtag) ); @@ -170,6 +169,7 @@ sub AddItemFromMarc { my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); $item_values->{more_subfields_xml} = _get_unlinked_subfields_xml($unlinked_item_subfields); $item_values->{biblionumber} = $biblionumber; + $item_values->{biblioitemnumber} = $params->{biblioitemnumber}; $item_values->{cn_source} = delete $item_values->{'items.cn_source'}; # Because of C4::Biblio::_disambiguate $item_values->{cn_sort} = delete $item_values->{'items.cn_sort'}; # Because of C4::Biblio::_disambiguate my $item = Koha::Item->new( $item_values )->store({ skip_record_index => $params->{skip_record_index} }); -- 2.30.2