From aacefca565a0242f361a7df3eb91de9d4bf55c39 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 10 Feb 2009 16:38:11 -0600 Subject: [PATCH] reduce bib fetches during search and OPAC display Speed up bib search and OPAC bib display, especially when the XSLT OPAC results and details display sysprefs are ON, by passing an existing MARC::Record object to three functions: C4::Biblio::get_biblio_authorised_values() C4::XSLT::XSLTParse4Display() C4::XSLT::transformMARCXML4XSLT (internal) These functions previously fetched the bib from the database, incurring the cost of DB retrieval and MARCXML parsing even though client code already had a MARC::Record object available. Signed-off-by: Galen Charlton Signed-off-by: Henri-Damien LAURENT --- C4/Biblio.pm | 4 ++-- C4/Search.pm | 4 ++-- C4/XSLT.pm | 10 +++++----- opac/opac-detail.pl | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index e911713302..f363259aaa 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -3253,6 +3253,7 @@ sub set_service_options { parameters: biblionumber + MARC::Record of the bib returns: a hashref malling the authorised value to the value set for this biblionumber @@ -3269,14 +3270,13 @@ sub set_service_options { sub get_biblio_authorised_values { my $biblionumber = shift; + my $record = shift; my $forlibrarian = 1; # are we in staff or opac? my $frameworkcode = GetFrameworkCode( $biblionumber ); my $authorised_values; - my $record = GetMarcBiblio( $biblionumber ) - or return $authorised_values; my $tagslib = GetMarcStructure( $forlibrarian, $frameworkcode ) or return $authorised_values; diff --git a/C4/Search.pm b/C4/Search.pm index 8499c0079f..da6ff09c60 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1250,7 +1250,7 @@ sub searchResults { # add imageurl to itemtype if there is one $oldbiblio->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} ); - $oldbiblio->{'authorised_value_images'} = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $oldbiblio->{'biblionumber'} ) ); + $oldbiblio->{'authorised_value_images'} = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $oldbiblio->{'biblionumber'}, $marcrecord ) ); (my $aisbn) = $oldbiblio->{isbn} =~ /([\d-]*[X]*)/; $aisbn =~ s/-//g; $oldbiblio->{amazonisbn} = $aisbn; @@ -1489,7 +1489,7 @@ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g; # XSLT processing of some stuff if (C4::Context->preference("XSLTResultsDisplay") && !$scan) { - my $newxmlrecord = XSLTParse4Display($oldbiblio->{biblionumber},C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACResults.xsl"); + my $newxmlrecord = XSLTParse4Display($oldbiblio->{biblionumber}, $marcrecord, C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACResults.xsl"); $oldbiblio->{XSLTResultsRecord} = $newxmlrecord; } diff --git a/C4/XSLT.pm b/C4/XSLT.pm index cf9c51bc88..0fbfda159b 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -47,13 +47,13 @@ C4::XSLT - Functions for displaying XSLT-generated content =head1 transformMARCXML4XSLT -=head2 replaces codes with authorized values in a MARCXML record +=head2 replaces codes with authorized values in a MARC::Record object =cut sub transformMARCXML4XSLT { - my ($biblionumber) = @_; - my $record = GetMarcBiblio($biblionumber); + my ($biblionumber, $orig_record) = @_; + my $record = $orig_record->clone(); # not updating original record; this may be unnecessarily paranoid my $biblio = GetBiblioData($biblionumber); my $frameworkcode = GetFrameworkCode($biblionumber); my $tagslib = &GetMarcStructure(1,$frameworkcode); @@ -109,9 +109,9 @@ sub getAuthorisedValues4MARCSubfields { my $stylesheet; sub XSLTParse4Display { - my ($biblionumber,$xslfile) = @_; + my ($biblionumber, $orig_record, $xslfile) = @_; # grab the XML, run it through our stylesheet, push it out to the browser - my $record = transformMARCXML4XSLT($biblionumber); + my $record = transformMARCXML4XSLT($biblionumber, $orig_record); my $itemsxml = buildKohaItemsNamespace($biblionumber); my $xmlrecord = $record->as_xml(); $xmlrecord =~ s/\<\/record\>/$itemsxml\<\/record\>/; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 794dea739d..708a1607cb 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -57,10 +57,11 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( ); my $biblionumber = $query->param('biblionumber') || $query->param('bib'); +my $record = GetMarcBiblio($biblionumber); $template->param( biblionumber => $biblionumber ); # XSLT processing of some stuff if (C4::Context->preference("XSLTDetailsDisplay") ) { - my $newxmlrecord = XSLTParse4Display($biblionumber,C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACDetail.xsl"); + my $newxmlrecord = XSLTParse4Display($biblionumber, $record, C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACDetail.xsl"); $template->param('XSLTBloc' => $newxmlrecord); } @@ -110,7 +111,7 @@ foreach my $subscription (@subscriptions) { $dat->{'count'} = scalar(@items); -my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber ) ); +my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) ); my $norequests = 1; my $branches = GetBranches(); @@ -159,7 +160,6 @@ for my $itm (@items) { ## get notes and subjects from MARC record my $dbh = C4::Context->dbh; my $marcflavour = C4::Context->preference("marcflavour"); -my $record = GetMarcBiblio($biblionumber); my $marcnotesarray = GetMarcNotes ($record,$marcflavour); my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); -- 2.20.1