X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FSQLHelper.pm;h=e1cb5d0a9aa35e8787d95e867c69077184d2a87f;hb=b82a10b3422b84e6a684621fb6fdda6c7a0563eb;hp=cf425fd24aa56f6d5461fb9c906e8d00f52bd550;hpb=c0234dd9b9649063acf2617fecf5c6efda38a532;p=koha_gimpoz diff --git a/C4/SQLHelper.pm b/C4/SQLHelper.pm index cf425fd24a..e1cb5d0a9a 100644 --- a/C4/SQLHelper.pm +++ b/C4/SQLHelper.pm @@ -27,6 +27,23 @@ 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', + expire_time => 600 + }; # cache for 10 mins + + memoize_memcached( '_get_columns', memcached => $memcached ); + memoize_memcached( 'GetPrimaryKeys', memcached => $memcached ); + } +}; + BEGIN { # set the version for version checking $VERSION = 0.5; @@ -38,11 +55,15 @@ BEGIN { SearchInTable UpdateInTable GetPrimaryKeys + clear_columns_cache ); %EXPORT_TAGS = ( all =>[qw( InsertInTable DeleteInTable SearchInTable UpdateInTable GetPrimaryKeys)] ); } +my $tablename; +my $hashref; + =head1 NAME C4::SQLHelper - Perl Module containing convenience functions for SQL Handling @@ -233,6 +254,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) @@ -247,16 +285,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