From 4dd798302a84acf5d4474affeaa61fc9c97ed68a 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 Signed-off-by: Andreas Roussos Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- misc/link_bibs_to_authorities.pl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/misc/link_bibs_to_authorities.pl b/misc/link_bibs_to_authorities.pl index 41a9edb63f..e7df4d57f6 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) { @@ -95,9 +98,10 @@ sub process_bibs { "SELECT biblionumber FROM biblio $bib_where ORDER BY biblionumber ASC"; my $sth = $dbh->prepare($sql); $sth->execute(); + my $linker_args = { tagtolink => $tagtolink, allowrelink => $allowrelink }; while ( my ($biblionumber) = $sth->fetchrow_array() ) { $num_bibs_processed++; - process_bib( $linker, $biblionumber, $tagtolink ); + process_bib( $linker, $biblionumber, $linker_args ); if ( not $test_only and ( $num_bibs_processed % $commit ) == 0 ) { print_progress_and_commit($num_bibs_processed); @@ -189,8 +193,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 +205,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.39.5