From 6c38cc23d95b63ae069f7cac2f7d8d97f9c941ae Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Tue, 29 Nov 2011 10:57:14 +0100 Subject: [PATCH 1/2] Bug 7276 : member entry Performance improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this patch : 9619 borrowers added in 31 Minutes, After : 68 seconds. This adds Hashref to table structure in C4::SQLHelper to speed up bulk edits. Signed-off-by: Stéphane Delaune Signed-off-by: Chris Cormack --- C4/SQLHelper.pm | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/C4/SQLHelper.pm b/C4/SQLHelper.pm index cf425fd24a..900e40dba5 100644 --- a/C4/SQLHelper.pm +++ b/C4/SQLHelper.pm @@ -27,6 +27,22 @@ use C4::Debug; require Exporter; use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); +eval { + my $servers = C4::Context->config('memcached_servers'); + if ($servers) { + require Memoize::Memcached; + import Memoize::Memcached qw(memoize_memcached); + + my $memcached = { + servers => [$servers], + key_prefix => C4::Context->config('memcached_namespace') || 'koha', + }; + + memoize_memcached( '_get_columns', memcached => $memcached, expire_time => 600000 ); #cache for 10 minutes + memoize_memcached( 'GetPrimaryKeys', memcached => $memcached, expire_time => 600000 ); #cache for 10 minutes + } +}; + BEGIN { # set the version for version checking $VERSION = 0.5; @@ -43,6 +59,9 @@ BEGIN { ); } +my $tablename; +my $hashref; + =head1 NAME C4::SQLHelper - Perl Module containing convenience functions for SQL Handling @@ -247,16 +266,24 @@ With =cut sub _get_columns($) { - my ($tablename)=@_; - my $dbh=C4::Context->dbh; - my $sth=$dbh->prepare_cached(qq{SHOW COLUMNS FROM $tablename }); - $sth->execute; - my $columns= $sth->fetchall_hashref(qw(Field)); + my ($tablename) = @_; + unless ( exists( $hashref->{$tablename} ) ) { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare_cached(qq{SHOW COLUMNS FROM $tablename }); + $sth->execute; + my $columns = $sth->fetchall_hashref(qw(Field)); + $hashref->{$tablename} = $columns; + } + return $hashref->{$tablename}; } =head2 _filter_columns - _filter_columns($tablename,$research, $filtercolumns) +=over 4 + +_filter_columns($tablename,$research, $filtercolumns) + +=back Given - a tablename From 94516e7f2a4c8ff1026e0a4a4ef9cefb9fe0c23d Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Wed, 7 Dec 2011 11:07:23 +1300 Subject: [PATCH 2/2] Bug 7276 : Follow up, adding a sub to clear the cache Signed-off-by: Paul Poulain --- C4/SQLHelper.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/C4/SQLHelper.pm b/C4/SQLHelper.pm index 900e40dba5..41c5a9f5c1 100644 --- a/C4/SQLHelper.pm +++ b/C4/SQLHelper.pm @@ -54,6 +54,7 @@ BEGIN { SearchInTable UpdateInTable GetPrimaryKeys + clear_columns_cache ); %EXPORT_TAGS = ( all =>[qw( InsertInTable DeleteInTable SearchInTable UpdateInTable GetPrimaryKeys)] ); @@ -252,6 +253,23 @@ sub GetPrimaryKeys($) { return grep { $hash_columns->{$_}->{'Key'} =~/PRI/i} keys %$hash_columns; } + +=head2 clear_columns_cache + + C4::SQLHelper->clear_columns_cache(); + +cleans the internal cache of sysprefs. Please call this method if +you update a tables structure. Otherwise, your new changes +will not be seen by this process. + +=cut + +sub clear_columns_cache { + %$hashref = (); +} + + + =head2 _get_columns _get_columns($tablename)