Bug 15263: XSLT display fetches sysprefs for every result processed
authorMirko Tietgen <mirko@abunchofthings.net>
Sun, 29 Nov 2015 19:35:19 +0000 (20:35 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Wed, 4 May 2016 13:40:31 +0000 (13:40 +0000)
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 <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Search.pm
C4/XSLT.pm

index edf5847..017d172 100644 (file)
@@ -1882,6 +1882,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++ ) {
 
@@ -2209,9 +2216,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
         }
 
index 7ca4f0d..e74a742 100644 (file)
@@ -160,13 +160,39 @@ sub _get_best_default_xslt_filename {
     return $xslfilename;
 }
 
+sub _get_xslt_sysprefs {
+    my $sysxml = "<sysprefs>\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 OpacSuppression / )
+    {
+        my $sp = C4::Context->preference( $syspref );
+        next unless defined($sp);
+        $sysxml .= "<syspref name=\"$syspref\">$sp</syspref>\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 .= "<syspref name=\"singleBranchMode\">$singleBranchMode</syspref>\n";
+
+    $sysxml .= "</sysprefs>\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');
@@ -201,28 +227,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 = "<sysprefs>\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 OpacSuppression / )
-    {
-        my $sp = C4::Context->preference( $syspref );
-        next unless defined($sp);
-        $sysxml .= "<syspref name=\"$syspref\">$sp</syspref>\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 .= "<syspref name=\"singleBranchMode\">$singleBranchMode</syspref>\n";
-
-    $sysxml .= "</sysprefs>\n";
     $xmlrecord =~ s/\<\/record\>/$itemsxml$sysxml\<\/record\>/;
     if ($fixamps) { # We need to correct the HTML entities that Zebra outputs
         $xmlrecord =~ s/\&amp;amp;/\&amp;/g;