[Koha-patches] [PATCH] Caching for authorised values

Frédéric Demians f.demians at tamil.fr
Wed Jun 17 22:00:18 CEST 2009


Even without mod_perl this caching improve performances
on OPAC result page. XSLT.pm decoding authorised values
for each record, it results something like about
7000 MySQL fetchrow...

With mod_perl, the cache must be emptied after updating
an authorized value category in pro interface.
---
 C4/Koha.pm |   39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/C4/Koha.pm b/C4/Koha.pm
index b4ce84b..8ea0bde 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -1002,23 +1002,30 @@ C<$category> returns authorised values for just one category (optional).
 
 =cut
 
-sub GetAuthorisedValues {
-    my ($category,$selected) = @_;
-	my @results;
-    my $dbh      = C4::Context->dbh;
-    my $query    = "SELECT * FROM authorised_values";
-    $query .= " WHERE category = '" . $category . "'" if $category;
+my %auth_values_hash;
 
-    my $sth = $dbh->prepare($query);
-    $sth->execute;
-	while (my $data=$sth->fetchrow_hashref) {
-		if ($selected eq $data->{'authorised_value'} ) {
-			$data->{'selected'} = 1;
-		}
-        push @results, $data;
-	}
-    #my $data = $sth->fetchall_arrayref({});
-    return \@results; #$data;
+sub GetAuthorisedValues {
+    my ( $category, $selected ) = @_;
+
+    my $category_slot = $category || '_ALL_';
+    my $auth_values = $auth_values_hash{ $category_slot };
+    unless ( $auth_values ) {
+	    my @results;
+        my $dbh      = C4::Context->dbh;
+        my $query    = "SELECT * FROM authorised_values";
+        $query .= " WHERE category = '" . $category . "'" if $category;
+        my $sth = $dbh->prepare($query);
+        $sth->execute;
+	    while ( my $data=$sth->fetchrow_hashref ) {
+            push( @results, $data );
+	    }
+        $auth_values = \@results;
+        $auth_values_hash{ $category_slot } = $auth_values;
+    }
+    foreach my $auth ( @$auth_values ) {
+        $auth->{ selected } = $auth->{ authorised_value } eq $selected;
+    }
+    return $auth_values;
 }
 
 =head2 GetAuthorisedValueCategories
-- 
1.5.6.5




More information about the Koha-patches mailing list