[Koha-patches] [PATCH] reduce bib fetches during search and OPAC display
Galen Charlton
galen.charlton at liblime.com
Tue Feb 10 23:38:11 CET 2009
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.
---
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 44d9fdb..04a967d 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 f950215..c3b715a 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 cf9c51b..0fbfda1 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 de61ce3..24f59b0 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);
--
1.5.5.GIT
More information about the Koha-patches
mailing list