From 70325d48a0fa71a0937b40bf76ead2e841e90697 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 18 May 2021 15:59:53 +0000 Subject: [PATCH] Bug 28375: Inefficiencies in fetching COinS This patchset adds an 'interface' parameter to XSLTParseForDisplay to avoid fetching coins when not needed Additionally we move some logic from the scripts to searchResults to avoid an extra fetch fo the biblio object To test: 1 - Enable COinSinOPACResults syspref 2 - Also enable OPACShowOpenURL and OPACOpenURLItemTypes - adding an itemtype that you can find 3 - Perform a search on the OPAC and confirm coins are included and openurl shown 4 - Perform a search on staff client and confirm openurls do not show 5 - Apply patch 6 - Results should be the same Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- C4/Search.pm | 7 ++++++- C4/XSLT.pm | 3 ++- catalogue/detail.pl | 2 ++ opac/opac-detail.pl | 2 ++ opac/opac-search.pl | 5 ----- opac/opac-shelves.pl | 1 + opac/opac-tags.pl | 1 + virtualshelves/shelves.pl | 1 + 8 files changed, 15 insertions(+), 7 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 14935ab731..35b6fbfe52 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -2017,13 +2017,18 @@ sub searchResults { ), fix_amps => 1, hidden_items => \@hiddenitems, - xslt_variables => $xslt_variables + xslt_variables => $xslt_variables, + interface => $search_context->{'interface'} } ); } my $biblio_object = Koha::Biblios->find( $oldbiblio->{biblionumber} ); $oldbiblio->{biblio_object} = $biblio_object; + $oldbiblio->{coins} = eval { $biblio_object->get_coins } + if $biblio_object + && C4::Context->preference('COinSinOPACResults') + && $is_opac; my $can_place_holds = 1; # if biblio level itypes are used and itemtype is notforloan, it can't be reserved either diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 8c2b4c1bcd..546667a69d 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -179,6 +179,7 @@ sub XSLTParse4Display { my $hidden_items = $params->{hidden_items} || []; my $variables = $params->{xslt_variables}; my $items_rs = $params->{items_rs}; + my $interface = $params->{interface}; die "Mandatory \$params->{xsl_syspref} was not provided, called with biblionumber $params->{biblionumber}" if not defined $params->{xsl_syspref}; @@ -208,7 +209,7 @@ sub XSLTParse4Display { $variables ||= {}; my $biblio; - if (C4::Context->preference('OPACShowOpenURL')) { + if ( $interface eq 'opac' && C4::Context->preference('OPACShowOpenURL')) { my @biblio_itemtypes; $biblio //= Koha::Biblios->find($biblionumber); if (C4::Context->preference('item-level_itypes')) { diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 3af82774ce..479e7f4895 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -261,6 +261,7 @@ if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { record => $part, xsl_syspref => "XSLTResultsDisplay", fix_amps => 1, + interface => 'intranet' } ); } @@ -284,6 +285,7 @@ $template->param( xsl_syspref => "XSLTDetailsDisplay", fix_amps => 1, xslt_variables => $xslt_variables, + interface => 'intranet' }), ); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 1e74df6279..0b427aa0a6 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -612,6 +612,7 @@ if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { record => $part, xsl_syspref => 'OPACXSLTResultsDisplay', fix_amps => 1, + interface => 'opac' } ); } @@ -647,6 +648,7 @@ $template->param( xsl_syspref => 'OPACXSLTDetailsDisplay', fix_amps => 1, xslt_variables => $variables, + interface => 'opac' }), ); diff --git a/opac/opac-search.pl b/opac/opac-search.pl index c0f7ca5d8c..f0b150dde9 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -659,11 +659,6 @@ for (my $i=0;$i<@servers;$i++) { $res->{'incart'} = 1; } - if (C4::Context->preference('COinSinOPACResults')) { - my $biblio = Koha::Biblios->find( $res->{'biblionumber'} ); - # Catch the exception as Koha::Biblio::Metadata->record can explode if the MARCXML is invalid - $res->{coins} = $biblio ? eval {$biblio->get_coins} : q{}; # FIXME This should be moved at the beginning of the @newresults loop - } if ( C4::Context->preference( "Babeltheque" ) and $res->{normalized_isbn} ) { if( my $isbn = Business::ISBN->new( $res->{normalized_isbn} ) ) { $isbn = $isbn->as_isbn13->as_string; diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index e228b3dfb0..b9f60f2d30 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -416,6 +416,7 @@ if ( $op eq 'view' ) { fix_amps => 1, xslt_variables => $variables, items_rs => $items->reset, + interface => 'opac' } ); diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl index 4aec61ee73..c5c85029e7 100755 --- a/opac/opac-tags.pl +++ b/opac/opac-tags.pl @@ -293,6 +293,7 @@ if ($loggedinuser) { fix_amps => 1, hidden_items => \@hidden_items, xslt_variables => $variables + interface => 'opac' } ); diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index fa92cfcd6e..08b99a16be 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -293,6 +293,7 @@ if ( $op eq 'view' ) { record => $record, xsl_syspref => 'XSLTListsDisplay', fix_amps => 1, + interface => 'intranet' } ); -- 2.39.5