From cd98d00ad5bcca6f26df524fd4332631cceea1a1 Mon Sep 17 00:00:00 2001 From: Mirko Tietgen Date: Sun, 29 Nov 2015 20:35:19 +0100 Subject: [PATCH] Bug 15263: XSLT display fetches sysprefs for every result processed On search, every single result goes through some XSLT processing. This includes fetching the relevant sysprefs every single time. We should do it only once per search. Signed-off-by: Tomas Cohen Arazi --- C4/Search.pm | 13 ++++++++++--- C4/XSLT.pm | 53 +++++++++++++++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index fcbb660..58f9383 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1864,6 +1864,13 @@ sub searchResults { # We get the biblionumber position in MARC my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber',''); + # set stuff for XSLT processing here once, not later again for every record we retrieved + my $interface = $search_context eq 'opac' ? 'OPAC' : ''; + my $xslsyspref = $interface . "XSLTResultsDisplay"; + my $xslfile = C4::Context->preference($xslsyspref); + my $lang = C4::Languages::getlanguage(); + my ($sysxml) = C4::XSLT::_get_xslt_sysprefs(); + # loop through all of the records we've retrieved for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) { @@ -2192,9 +2199,9 @@ sub searchResults { } # XSLT processing of some stuff - my $interface = $search_context eq 'opac' ? 'OPAC' : ''; - if (!$scan && C4::Context->preference($interface . "XSLTResultsDisplay")) { - $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $interface."XSLTResultsDisplay", 1, \@hiddenitems); + # we fetched the sysprefs already before the loop through all retrieved record! + if (!$scan && $xslfile) { + $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile); # the last parameter tells Koha to clean up the problematic ampersand entities that Zebra outputs } diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 5622e5f..eed1d09 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -157,13 +157,39 @@ sub _get_best_default_xslt_filename { return $xslfilename; } +sub _get_xslt_sysprefs { + my $sysxml = "\n"; + foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow + DisplayOPACiconsXSLT URLLinkText viewISBD + OPACBaseURL TraceCompleteSubfields UseICU + UseAuthoritiesForTracings TraceSubjectSubdivisions + Display856uAsImage OPACDisplay856uAsImage + UseControlNumber IntranetBiblioDefaultView BiblioDefaultView + singleBranchMode OPACItemLocation DisplayIconsXSLT + AlternateHoldingsField AlternateHoldingsSeparator + TrackClicks opacthemes IdRef / ) + { + my $sp = C4::Context->preference( $syspref ); + next unless defined($sp); + $sysxml .= "$sp\n"; + } + + # singleBranchMode was a system preference, but no longer is + # we can retain it here for compatibility + my $singleBranchMode = Koha::Libraries->search->count == 1; + $sysxml .= "$singleBranchMode\n"; + + $sysxml .= "\n"; + return $sysxml; +} + sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items ) = @_; - my $xslfilename = C4::Context->preference($xslsyspref); + my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang ) = @_; + #my $xslfilename = C4::Context->preference($xslsyspref); if ( $xslfilename =~ /^\s*"?default"?\s*$/i ) { my $htdocs; my $theme; - my $lang = C4::Languages::getlanguage(); + # my $lang = C4::Languages::getlanguage(); my $xslfile; if ($xslsyspref eq "XSLTDetailsDisplay") { $htdocs = C4::Context->config('intrahtdocs'); @@ -198,28 +224,7 @@ sub XSLTParse4Display { my $record = transformMARCXML4XSLT($biblionumber, $orig_record); my $itemsxml = buildKohaItemsNamespace($biblionumber, $hidden_items); my $xmlrecord = $record->as_xml(C4::Context->preference('marcflavour')); - my $sysxml = "\n"; - foreach my $syspref ( qw/ hidelostitems OPACURLOpenInNewWindow - DisplayOPACiconsXSLT URLLinkText viewISBD - OPACBaseURL TraceCompleteSubfields UseICU - UseAuthoritiesForTracings TraceSubjectSubdivisions - Display856uAsImage OPACDisplay856uAsImage - UseControlNumber IntranetBiblioDefaultView BiblioDefaultView - OPACItemLocation DisplayIconsXSLT - AlternateHoldingsField AlternateHoldingsSeparator - TrackClicks opacthemes IdRef / ) - { - my $sp = C4::Context->preference( $syspref ); - next unless defined($sp); - $sysxml .= "$sp\n"; - } - - # singleBranchMode was a system preference, but no longer is - # we can retain it here for compatibility - my $singleBranchMode = Koha::Libraries->search->count == 1; - $sysxml .= "$singleBranchMode\n"; - $sysxml .= "\n"; $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/; if ($fixamps) { # We need to correct the HTML entities that Zebra outputs $xmlrecord =~ s/\&amp;/\&/g; -- 2.7.4