From 8bbe03aa23a0ee67b95c566ba24af75e69d82be3 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 8 Apr 2013 14:20:53 -0400 Subject: [PATCH] Bug 10004 - Delay batch record count updates until the end of the z39.50 search Right now when a z39.50 search is run, _update_batch_record_counts is run for each record. If multiple duplicate bibs are in the search, it will be run for each of them. For Koha installations with very large numbers of batches, this can cause significant slowdowns. It would be better to delay this update until the very end so we can update each batch only once. In addition, we can fork this process, as it is not neccessary to wait for it before displaying results. Test Plan: 1) Apply patch 2) Perform a z39.50 search --- C4/Breeding.pm | 37 +++++++++++++++++++++++++++++++++---- C4/ImportBatch.pm | 6 ++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/C4/Breeding.pm b/C4/Breeding.pm index 4d26be6..bebd166 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -25,6 +25,7 @@ use C4::Koha; use C4::Charset; use MARC::File::USMARC; use C4::ImportBatch; +use List::MoreUtils qw(uniq); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -71,7 +72,7 @@ C4::Breeding : module to add biblios to import_records via =cut sub ImportBreeding { - my ($marcrecords,$overwrite_biblio,$filename,$encoding,$z3950random,$batch_type) = @_; + my ( $marcrecords, $overwrite_biblio, $filename, $encoding, $z3950random, $batch_type, $update_counts ) = @_; my @marcarray = split /\x1D/, $marcrecords; my $dbh = C4::Context->dbh; @@ -140,7 +141,7 @@ sub ImportBreeding { if ($breedingid && $overwrite_biblio eq '1') { ModBiblioInBatch($breedingid, $marcrecord); } else { - my $import_id = AddBiblioToBatch($batch_id, $imported, $marcrecord, $encoding, $z3950random); + my $import_id = AddBiblioToBatch($batch_id, $imported, $marcrecord, $encoding, $z3950random, $update_counts); $breedingid = $import_id; } $imported++; @@ -148,7 +149,7 @@ sub ImportBreeding { } } } - return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid); + return ( $notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid, $batch_id ); } @@ -341,6 +342,7 @@ sub Z3950Search { $oResult[$z] = $oConnection[$z]->search_pqf($query); } + my @batch_id; while ( $nremaining-- ) { my $k; my $event; @@ -382,7 +384,13 @@ sub Z3950Search { # pad | and ( with spaces to allow line breaks in the HTML $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn}; $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn}; - my ($notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid)= ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' ); + + my ( $notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid, $batch_id ) = + ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950', 0 ); + + # Delay the updating of batch record counts until the very end + push( @batch_id, $batch_id ); + my %row_data; $row_data{server} = $servername[$k]; $row_data{isbn} = $oldbiblio->{isbn}; @@ -427,6 +435,27 @@ sub Z3950Search { servers => \@servers, errconn => \@errconn ); + + # Process the delayed batch record count updates + my $pid; + if ( $pid = fork ) { + # Parent, continue on as usual + + # prevent parent exiting from + # destroying the kid's database handle + # FIXME: according to DBI doc, this may not work for Oracle + $dbh->{InactiveDestroy} = 1; + warn "TEST1"; + } else { + close STDOUT; + close STDERR; + + @batch_id = uniq(@batch_id); + foreach my $bid (@batch_id) { + UpdateBatchRecordCounts($bid); + } + } + warn "TEST2"; } 1; diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 5f46613..2a9d7d9 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -76,6 +76,8 @@ BEGIN { SetImportRecordStatus GetImportRecordMatches SetImportRecordMatches + + UpdateBatchRecordCounts ); } @@ -1446,6 +1448,10 @@ sub _update_batch_record_counts { $sth->finish(); } +sub UpdateBatchRecordCounts { + return _update_batch_record_counts( @_ ); +} + sub _get_commit_action { my ($overlay_action, $nomatch_action, $item_action, $overlay_status, $import_record_id, $record_type) = @_; -- 1.7.2.5