From 5e6b3a1ec78fedb8634717d58297b063b2846757 Mon Sep 17 00:00:00 2001 From: Jonathan Druart 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. I have enabled general_log in the MariaDB config file, the GET circ/circulation.pl?borrowernumber=42 There are 293 queries of the following form: SELECT me.variable, me.value, me.options, me.explanation, me.type FROM systempreferences me WHERE ( me.variable = 'MY_SYSPREF' ) Then benchmarking before and after this patch (using plackup, and the misc/plack/koha.psgi file with Profiler::NYTProf enabled): Before: Profile of /home/koha/perl5/bin/plackup for -2.07s (of 616ms), executing 158857 statements and 588479 subroutine calls in 427 source files and 73 string evals. 885 174ms 4.03s C4::Context::preference After: Profile of /home/koha/perl5/bin/plackup for -1.70s (of 349ms), executing 94273 statements and 397525 subroutine calls in 437 source files and 79 string evals. 1138 194ms 1.99s C4::Context::preference (calls) (exclusive time) (inclusive time) Could someone confirm that? --- C4/Context.pm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index e314f5a..eb685e8 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -525,13 +525,10 @@ sub preference { if ( defined $ENV{"OVERRIDE_SYSPREF_$var"} ) { $value = $ENV{"OVERRIDE_SYSPREF_$var"}; } else { - my $syspref; - eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; - $value = $syspref ? $syspref->value() : undef; + map { $sysprefs{lc $_->{variable}} = $_->{value} or undef} @{ Koha::Config::SysPrefs->search()->unblessed }; } - $sysprefs{lc $var} = $value; - return $value; + return $sysprefs{lc $var}; } sub boolean_preference { -- 2.1.0