From cacc16c659ba64ea75602c5122e87c8337a11bbe Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 13 Jan 2023 20:07:01 +0000 Subject: [PATCH] Bug 32250: Only reindex records when commiting This patch adds an array to catch updated bibs, and defers indexing until a batch of changes is committed To test: 1 - Set LinkerModule system preference to either first or last match Alternate this between runs of the linker to ensure changes are made 2 - Set SearchEngine to Elasticsearch and reindex (to ensure index is built) 3 - perl misc/link_bibs_to_authorities.pl -v 4 - Check Admin->Jobs and see that many ES index jobs are queued 5 - Apply patch 6 - perl misc/link_bibs_to_authorities.pl -v 7 - Check Admin->Jobs and see that 1 index per commit from is enqueued Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- misc/link_bibs_to_authorities.pl | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/misc/link_bibs_to_authorities.pl b/misc/link_bibs_to_authorities.pl index 981da7f4af..87b8c9feeb 100755 --- a/misc/link_bibs_to_authorities.pl +++ b/misc/link_bibs_to_authorities.pl @@ -17,6 +17,9 @@ use Time::HiRes qw( time ); use POSIX qw( ceil strftime ); use Module::Load::Conditional qw( can_load ); +use Koha::SearchEngine; +use Koha::SearchEngine::Indexer; + sub usage { pod2usage( -verbose => 2 ); exit; @@ -75,6 +78,9 @@ my %unlinked_headings; my %linked_headings; my %fuzzy_headings; my $dbh = C4::Context->dbh; +my @updated_biblios = (); +my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $dbh->{AutoCommit} = 0; process_bibs( $linker, $bib_limit, $auth_limit, $commit, { tagtolink => $tagtolink, allowrelink => $allowrelink }); $dbh->commit(); @@ -105,6 +111,7 @@ sub process_bibs { } if ( not $test_only ) { + $indexer->index_records( \@updated_biblios, "specialUpdate", "biblioserver" ); $dbh->commit; } @@ -226,7 +233,12 @@ sub process_bib { ); } if ( not $test_only ) { - ModBiblio( $record, $biblionumber, $frameworkcode, { disable_autolink => 1, skip_holds_queue => 1 }); + ModBiblio( $record, $biblionumber, $frameworkcode, { + disable_autolink => 1, + skip_holds_queue => 1, + skip_record_index =>1 + }); + push @updated_biblios, $biblionumber; #Last param is to note ModBiblio was called from linking script and bib should not be linked again $num_bibs_modified++; } @@ -236,6 +248,8 @@ sub process_bib { sub print_progress_and_commit { my $recs = shift; $dbh->commit(); + $indexer->index_records( \@updated_biblios, "specialUpdate", "biblioserver" ); + @updated_biblios = (); print "... processed $recs records\n"; } -- 2.39.5