From 26169e1ee354d9069b511fcb4e17da76e74f3b9b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 Jan 2021 12:01:18 +0100 Subject: [PATCH] Bug 27343: Cache get_all_subpermissions return The permissions are fetched for every hit, we should cache them in L1. --- C4/Auth.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 6db8ee5b91..771c457fc5 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -33,6 +33,7 @@ use C4::Languages; use C4::Search::History; use Koha; use Koha::Caches; +use Koha::Cache::Memory::Lite; use Koha::AuthUtils qw(get_script_name hash_password); use Koha::Checkouts; use Koha::DateUtils qw(dt_from_string); @@ -2086,16 +2087,25 @@ of the subpermission. =cut sub get_all_subpermissions { + + my $memory_cache = Koha::Cache::Memory::Lite->get_instance(); + my $cache_key = "all_subpermissions"; + + my $cached = $memory_cache->get_from_cache($cache_key); + return $cached if $cached; + my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( "SELECT flag, code + my $permissions = $dbh->selectall_arrayref( q|SELECT flag, code FROM permissions - JOIN userflags ON (module_bit = bit)" ); - $sth->execute(); + JOIN userflags ON (module_bit = bit)|, { Slice => {} } ); my $all_perms = {}; - while ( my $perm = $sth->fetchrow_hashref ) { + for my $perm ( @$permissions ) { $all_perms->{ $perm->{'flag'} }->{ $perm->{'code'} } = 1; } + + $memory_cache->set_in_cache( $cache_key, $all_perms ); + return $all_perms; } -- 2.20.1