cache $sth->execute in GetAuthorisedValueDesc
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Oct 2010 14:13:42 +0000 (16:13 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 6 Nov 2011 04:44:55 +0000 (05:44 +0100)
309 -> 25 times for search page

C4/Biblio.pm

index 4a9735f..944c782 100644 (file)
@@ -1338,6 +1338,8 @@ descriptions rather than normal ones when they exist.
 
 =cut
 
+my $_auth_val;
+
 sub GetAuthorisedValueDesc {
     my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_;
     my $dbh = C4::Context->dbh;
@@ -1361,9 +1363,16 @@ sub GetAuthorisedValueDesc {
     }
 
     if ( $category ne "" ) {
-        my $sth = $dbh->prepare( "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" );
-        $sth->execute( $category, $value );
-        my $data = $sth->fetchrow_hashref;
+
+       my $data;
+
+       if ( $data = $_auth_val->{$category}->{$value} ) {
+warn "XXX auth_val hit: $category $value\n";
+       } else {
+               my $sth = $dbh->prepare( "SELECT lib, lib_opac FROM authorised_values WHERE category = ? AND authorised_value = ?" );
+               $sth->execute( $category, $value );
+               $_auth_val->{$category}->{$value} = $data = $sth->fetchrow_hashref;
+       }
         return ( $opac && $data->{'lib_opac'} ) ? $data->{'lib_opac'} : $data->{'lib'};
     } else {
         return $value;    # if nothing is found return the original value