@@ -, +, @@ added - call to ModZebra was done after EACH item added, but it was called only with main biblionumber only, so call was the same on each of requests - and also time spent in that ModZebra sub increased with every next hundred items in DB for that element: so adding every next 100 was slower and slower, - now it's called only once (by adding some extra parameter to "AddItem*" sub set in postponed mode) - and now adding of elements not so heavily depends from how much items was in DB before. so might be not so noticeably fast on empty DBs) - go to one of bibliotitems cataloguing/additem.pl?biblionumber=XXX pages - press button "add multiple copies of this item", put 1000 on slower machines, 5000 on faster - start measuring time + submit page/form --- C4/Items.pm | 25 +++++++++++++++++++------ cataloguing/additem.pl | 6 +++++- 2 files changed, 24 insertions(+), 7 deletions(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -143,7 +143,7 @@ sub CartToShelf { =head2 AddItemFromMarc my ($biblionumber, $biblioitemnumber, $itemnumber) - = AddItemFromMarc($source_item_marc, $biblionumber); + = AddItemFromMarc($source_item_marc, $biblionumber[, $hash_params]); Given a MARC::Record object containing an embedded item record and a biblionumber, create a new item record. @@ -151,7 +151,10 @@ record and a biblionumber, create a new item record. =cut sub AddItemFromMarc { - my ( $source_item_marc, $biblionumber ) = @_; + my $source_item_marc = shift; + my $biblionumber = shift; + my $hash_params = @_ ? shift : {}; + my $dbh = C4::Context->dbh; # parse item hash from MARC @@ -162,13 +165,13 @@ sub AddItemFromMarc { $localitemmarc->append_fields( $source_item_marc->field($itemtag) ); my $item = C4::Biblio::TransformMarcToKoha( $localitemmarc, $frameworkcode, 'items' ); my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode ); - return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields ); + return AddItem( $item, $biblionumber, $dbh, $frameworkcode, $unlinked_item_subfields, $hash_params ); } =head2 AddItem my ($biblionumber, $biblioitemnumber, $itemnumber) - = AddItem($item, $biblionumber[, $dbh, $frameworkcode, $unlinked_item_subfields]); + = AddItem($item, $biblionumber[, $dbh, $frameworkcode, $unlinked_item_subfields, $hash_params]); Given a hash containing item column names as keys, create a new Koha item record. @@ -177,13 +180,21 @@ The first two optional parameters (C<$dbh> and C<$frameworkcode>) do not need to be supplied for general use; they exist simply to allow them to be picked up from AddItemFromMarc. -The final optional parameter, C<$unlinked_item_subfields>, contains +Optional parameter, C<$unlinked_item_subfields>, contains an arrayref containing subfields present in the original MARC representation of the item (e.g., from the item editor) that are not mapped to C columns directly but should instead be stored in C and included in the biblio items tag for display and indexing. +The final optional parameter, C<$hash_params>, for now expected to contain +'postpone_indexes_update' key, which when true prevents calling of ModZebra sub +so this used when adding items in a batch and then ModZebra called in +C after the whole loop. + +$hash_params: + postpone_indexes_update => true / false + =cut sub AddItem { @@ -196,6 +207,7 @@ sub AddItem { if (@_) { $unlinked_item_subfields = shift; } + my $hash_params = @_ ? shift : {}; # needs old biblionumber and biblioitemnumber $item->{'biblionumber'} = $biblionumber; @@ -219,7 +231,8 @@ sub AddItem { $item->{'itemnumber'} = $itemnumber; - C4::Biblio::ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver" ); + C4::Biblio::ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver" ) + unless $hash_params->{postpone_indexes_update}; logaction( "CATALOGUING", "ADD", $itemnumber, "item" ) if C4::Context->preference("CataloguingLog"); --- a/cataloguing/additem.pl +++ a/cataloguing/additem.pl @@ -600,7 +600,8 @@ if ($op eq "additem") { # Adding the item if (!$exist_itemnumber) { - my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber); + my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = + AddItemFromMarc( $record, $biblionumber, { postpone_indexes_update => 1 } ); set_item_default_location($oldbibitemnum); # We count the item only if it was really added @@ -614,6 +615,9 @@ if ($op eq "additem") { # Preparing the next iteration $oldbarcode = $barcodevalue; } + + C4::Biblio::ModZebra( $biblionumber, "specialUpdate", "biblioserver" ); + undef($itemrecord); } } --