Bug 30824: Improve performance of BatchCommitItems
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 <martin.renvoize@ptfs-europe.com> Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
71a95d3557
commit
bb6be983d6
|
|
@ -620,7 +620,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;
|
||||
|
|
@ -706,12 +706,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;
|
||||
|
||||
|
|
@ -736,7 +736,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'} );
|
||||
|
|
@ -774,7 +774,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 );
|
||||
|
|
|
|||
|
|
@ -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} });
|
||||
|
|
|
|||
Loading…
Reference in New Issue