reduce bib fetches during search and OPAC display
authorGalen Charlton <galen.charlton@liblime.com>
Tue, 10 Feb 2009 22:38:11 +0000 (16:38 -0600)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Tue, 26 May 2009 19:14:57 +0000 (21:14 +0200)
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 <galen.charlton@liblime.com>
Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
C4/Biblio.pm
C4/Search.pm
C4/XSLT.pm
opac/opac-detail.pl

index e911713..f363259 100644 (file)
@@ -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;
 
index 8499c00..da6ff09 100644 (file)
@@ -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;
         }
 
index cf9c51b..0fbfda1 100644 (file)
@@ -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\>/;
index 794dea7..708a160 100755 (executable)
@@ -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);