From c18ba9258d0b473d89c5fcd6f65d0de527f1d630 Mon Sep 17 00:00:00 2001 From: David Cook Date: Sun, 11 Oct 2020 23:47:45 +0000 Subject: [PATCH] Bug 26641: Optimize CatalogModuleRelink lookup This patch moves the CatalogModuleRelink lookup outside the loop to improve performance (especially for large databases), and includes a tester friendly test plan. Test plan: 0. Using koha-testing-docker 1. koha-shell -c "./misc/link_bibs_to_authorities.pl -l --test" kohadev 2. Note 436 bibs checked, 1315 headings linked, 676 headings unlinked 3. koha-shell -c "./misc/link_bibs_to_authorities.pl -l --test -g 700" kohadev 4. Note 436 bibs checked, 248 headings linked, 111 headings unlinked 5. Note output appear to all be names (rather than subjects or other authorities) 6. Note also that the 2nd run with -g 700 is almost 2x faster than without --- misc/link_bibs_to_authorities.pl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/misc/link_bibs_to_authorities.pl b/misc/link_bibs_to_authorities.pl index 41a9edb63f..18e3266936 100755 --- a/misc/link_bibs_to_authorities.pl +++ b/misc/link_bibs_to_authorities.pl @@ -37,6 +37,7 @@ my $auth_limit; my $bib_limit; my $commit = 100; my $tagtolink; +my $allowrelink = C4::Context->preference("CatalogModuleRelink") || ''; my $result = GetOptions( 'v|verbose' => \$verbose, @@ -79,13 +80,15 @@ my %linked_headings; my %fuzzy_headings; my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; -process_bibs( $linker, $bib_limit, $auth_limit, $commit, $tagtolink ); +process_bibs( $linker, $bib_limit, $auth_limit, $commit, { tagtolink => $tagtolink, allowrelink => $allowrelink }); $dbh->commit(); exit 0; sub process_bibs { - my ( $linker, $bib_limit, $auth_limit, $commit, $tagtolink ) = @_; + my ( $linker, $bib_limit, $auth_limit, $commit, $args ) = @_; + my $tagtolink = $args->{tagtolink}; + my $allowrelink = $args->{allowrelink}; my $bib_where = ''; my $starttime = time(); if ($bib_limit) { @@ -97,7 +100,7 @@ sub process_bibs { $sth->execute(); while ( my ($biblionumber) = $sth->fetchrow_array() ) { $num_bibs_processed++; - process_bib( $linker, $biblionumber, $tagtolink ); + process_bib( $linker, $biblionumber, { tagtolink => $tagtolink, allowrelink => $allowrelink } ); if ( not $test_only and ( $num_bibs_processed % $commit ) == 0 ) { print_progress_and_commit($num_bibs_processed); @@ -189,8 +192,9 @@ _FUZZY_HEADER_ sub process_bib { my $linker = shift; my $biblionumber = shift; - my $tagtolink = shift; - + my $args = shift; + my $tagtolink = $args->{tagtolink}; + my $allowrelink = $args->{allowrelink}; my $bib = GetMarcBiblio({ biblionumber => $biblionumber }); unless ( defined $bib ) { print @@ -200,7 +204,6 @@ sub process_bib { } my $frameworkcode = GetFrameworkCode($biblionumber); - my $allowrelink = C4::Context->preference("CatalogModuleRelink") || ''; my ( $headings_changed, $results ) = LinkBibHeadingsToAuthorities( $linker, $bib, $frameworkcode, $allowrelink, $tagtolink ); -- 2.11.0