From 04282ed97fb148ef1255789fb27aba48ecc58320 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 17 May 2022 12:29:40 +0000 Subject: [PATCH] Bug 30789: Improve performance of AddBiblio AddBiblio calls TransformMarcRecordToKoha. We are only interested in getting biblio and biblioitems info, so we can pass 'no_items' to save some field lookups Additionally we can pass the subfield structure we have already fetched into the subroutine TransformMarcToKohaOneField Testing with NYTProf I saw a reduction of ~6 seconds when importing ~400 bibs and ~1000 items i.e. I exported and imported the sample data (after removing duplicate 010 from record 72) To test: 1 - Stage and import some records 2 - Confirm it works the same before and after patch --- C4/Biblio.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 459a94510a..25917d488c 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -220,7 +220,7 @@ sub AddBiblio { # transform the data into koha-table style data SetUTF8Flag($record); - my $olddata = TransformMarcToKoha( $record, $frameworkcode ); + my $olddata = TransformMarcToKoha( $record, $frameworkcode, 'no_items' ); my $biblio = Koha::Biblio->new( { @@ -2326,7 +2326,7 @@ sub TransformMarcToKoha { foreach my $kohafield ( keys %{ $mss } ) { my ( $table, $column ) = split /[.]/, $kohafield, 2; next unless $tables{$table}; - my $val = TransformMarcToKohaOneField( $kohafield, $record ); + my $val = TransformMarcToKohaOneField( $kohafield, $record, $mss->{$kohafield} ); next if !defined $val; my $key = _disambiguate( $table, $column ); $result->{$key} = $val; @@ -2382,10 +2382,10 @@ sub _disambiguate { =cut sub TransformMarcToKohaOneField { - my ( $kohafield, $marc ) = @_; + my ( $kohafield, $marc, $mss ) = @_; my ( @rv, $retval ); - my @mss = GetMarcSubfieldStructureFromKohaField($kohafield); + my @mss = $mss? @{$mss} : GetMarcSubfieldStructureFromKohaField($kohafield); foreach my $fldhash ( @mss ) { my $tag = $fldhash->{tagfield}; my $sub = $fldhash->{tagsubfield}; -- 2.30.2