Bugzilla – Attachment 56012 Details for
Bug 15341
Performance - Retrieve all sysprefs at once
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15341: Retrieve all sysprefs at once
Bug-15341-Retrieve-all-sysprefs-at-once.patch (text/plain), 3.29 KB, created by
Jonathan Druart
on 2016-10-04 09:53:32 UTC
(
hide
)
Description:
Bug 15341: Retrieve all sysprefs at once
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-10-04 09:53:32 UTC
Size:
3.29 KB
patch
obsolete
>From 78af9486abaeae3ac05a92ff6b844ee362e14367 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 9 Dec 2015 15:18:08 +0000 >Subject: [PATCH] Bug 15341: Retrieve all sysprefs at once > >C4::Context->preference generates a call to Koha::Config::SysPrefs->find >for all different sysprefs we are searching for. >It seems to be a performance killer and be better to retrieve them all >together and then cache them all. >--- > C4/Context.pm | 42 ++++++++++++++++++++++++------------------ > 1 file changed, 24 insertions(+), 18 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 5f49bbe..fd3d19d 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -101,7 +101,6 @@ use C4::Boolean; > use C4::Debug; > use Koha; > use Koha::Config; >-use Koha::Config::SysPref; > use Koha::Config::SysPrefs; > > =head1 NAME >@@ -401,8 +400,9 @@ with this method. > > =cut > >-my $syspref_cache = Koha::Caches->get_instance('syspref'); >+my $sysprefs = {}; > my $use_syspref_cache = 1; >+ > sub preference { > my $self = shift; > my $var = shift; # The system preference to return >@@ -410,21 +410,27 @@ sub preference { > $var = lc $var; > > return $ENV{"OVERRIDE_SYSPREF_$var"} >- if defined $ENV{"OVERRIDE_SYSPREF_$var"}; >- >- my $cached_var = $use_syspref_cache >- ? $syspref_cache->get_from_cache("syspref_$var") >- : undef; >+ if defined $ENV{"OVERRIDE_SYSPREF_$var"}; >+ >+ my $cached_var; >+ if ($use_syspref_cache) { >+ unless (%$sysprefs) { >+ # first hit >+ my $syspref_cache = Koha::Caches->get_instance('sysprefs'); >+ $sysprefs = $syspref_cache->get_from_cache('sysprefs'); >+ unless ( $sysprefs and %$sysprefs) { >+ # L2 is not populated yet >+ map { $sysprefs->{ lc $_->{variable} } = $_->{value} or undef } @{ Koha::Config::SysPrefs->search()->unblessed }; >+ $syspref_cache->set_in_cache( 'sysprefs', $sysprefs ); >+ } >+ } >+ $cached_var = exists $sysprefs->{$var} ? $sysprefs->{$var} : undef; >+ } > return $cached_var if defined $cached_var; > > my $syspref; > eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; >- my $value = $syspref ? $syspref->value() : undef; >- >- if ( $use_syspref_cache ) { >- $syspref_cache->set_in_cache("syspref_$var", $value); >- } >- return $value; >+ return $syspref ? $syspref->value() : undef; > } > > sub boolean_preference { >@@ -477,7 +483,9 @@ will not be seen by this process. > > sub clear_syspref_cache { > return unless $use_syspref_cache; >+ my $syspref_cache = Koha::Caches->get_instance('sysprefs'); > $syspref_cache->flush_all; >+ $sysprefs = {}; > } > > =head2 set_preference >@@ -528,11 +536,8 @@ sub set_preference { > )->store(); > } > >- if ( $use_syspref_cache ) { >- $syspref_cache->set_in_cache( "syspref_$variable", $value ); >- } >- >- return $syspref; >+ $self->clear_syspref_cache; >+ return $self->preference($variable); > } > > =head2 delete_preference >@@ -550,6 +555,7 @@ sub delete_preference { > > if ( Koha::Config::SysPrefs->find( $var )->delete ) { > if ( $use_syspref_cache ) { >+ my $syspref_cache = Koha::Caches->get_instance('sysprefs'); > $syspref_cache->clear_from_cache("syspref_$var"); > } > >-- >2.8.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15341
:
45535
| 56012