From 4c55cc220fdeea6bd738fc6ab6e37c5a9c3876d0 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 --- 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 44d9fdbc7f..04a967da92 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -3135,6 +3135,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 @@ -3151,14 +3152,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 f950215706..c3b715aa1a 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1262,7 +1262,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; @@ -1492,7 +1492,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 de61ce3369..24f59b0bff 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.39.5