From 8a48be54d366f6722f2e249a3a2edc653485cb45 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 18 May 2021 13:20:07 +0000 Subject: [PATCH] Bug 28371: WIP A lot of our time is spent in transformMARC4XSLT We do a db lookup per authval, every time - adding some caching here (probably in a better way) quickly increases performance Additionally, passing through the framework code can save us a lookup each time. --- C4/Search.pm | 2 +- C4/XSLT.pm | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 0db460a808..deadfd8a52 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -2019,7 +2019,7 @@ sub searchResults { }); $record_processor->process($marcrecord); - $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables); + $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, $xslsyspref, 1, \@hiddenitems, $sysxml, $xslfile, $lang, $xslt_variables, $fw); } # 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 3cdf451b28..c16238addc 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -40,6 +40,7 @@ use vars qw(@ISA @EXPORT); my $engine; #XSLT Handler object my %authval_per_framework; +my %authval_descs; # Cache for tagfield-tagsubfield to decode per framework. # Should be preferably be placed in Koha-core... @@ -66,8 +67,8 @@ Is only used in this module currently. =cut sub transformMARCXML4XSLT { - my ($biblionumber, $record) = @_; - my $frameworkcode = GetFrameworkCode($biblionumber) || ''; + my ($biblionumber, $record, $frameworkcode ) = @_; + $frameworkcode //= GetFrameworkCode($biblionumber) || ''; my $tagslib = &GetMarcStructure(1, $frameworkcode, { unsafe => 1 }); my @fields; # FIXME: wish there was a better way to handle exceptions @@ -85,8 +86,15 @@ sub transformMARCXML4XSLT { my ( $letter, $value ) = @$subfield; # Replace the field value with the authorised value *except* for MARC21/NORMARC field 942$n (suppression in opac) if ( !( $tag eq '942' && $subfield->[0] eq 'n' ) || $marcflavour eq 'UNIMARC' ) { - $value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib ) - if $av->{ $tag }->{ $letter }; + if( defined $authval_descs{$frameworkcode.$tag.$letter.$value} ){ + $value = $authval_descs{$frameworkcode.$tag.$letter.$value}; + } else { + if( $av->{$tag}->{$letter} ){ + my $orig_val = $value; + $value = GetAuthorisedValueDesc( $tag, $letter, $value, '', $tagslib ); + $authval_descs{$frameworkcode.$tag.$letter.$orig_val} = $value; + } + } } push( @new_subfields, $letter, $value ); } @@ -190,7 +198,7 @@ sub get_xslt_sysprefs { } sub XSLTParse4Display { - my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang, $variables ) = @_; + my ( $biblionumber, $orig_record, $xslsyspref, $fixamps, $hidden_items, $sysxml, $xslfilename, $lang, $variables, $frameworkcode ) = @_; $sysxml ||= C4::Context->preference($xslsyspref); $xslfilename ||= C4::Context->preference($xslsyspref); @@ -241,7 +249,7 @@ sub XSLTParse4Display { } # grab the XML, run it through our stylesheet, push it out to the browser - my $record = transformMARCXML4XSLT($biblionumber, $orig_record); + my $record = transformMARCXML4XSLT($biblionumber, $orig_record, $frameworkcode); my $itemsxml; if ( $xslsyspref eq "OPACXSLTDetailsDisplay" || $xslsyspref eq "XSLTDetailsDisplay" || $xslsyspref eq "XSLTResultsDisplay" ) { $itemsxml = ""; #We don't use XSLT for items display on these pages -- 2.11.0