Bugzilla – Attachment 49370 Details for
Bug 15562
Make Koha more suitable for shared hosting with plack
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
bug_15562: Sysprefs cache is object property now
bug15562-Sysprefs-cache-is-object-property-now.patch (text/plain), 4.49 KB, created by
Srdjan Jankovic
on 2016-03-21 05:21:02 UTC
(
hide
)
Description:
bug_15562: Sysprefs cache is object property now
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2016-03-21 05:21:02 UTC
Size:
4.49 KB
patch
obsolete
>From e1277cb43cac8dddcde895850adf9bcaaaba5d08 Mon Sep 17 00:00:00 2001 >From: Srdjan <srdjan@catalyst.net.nz> >Date: Wed, 20 Jan 2016 19:09:23 +1300 >Subject: [PATCH] bug_15562: Sysprefs cache is object property now > >https://bugs.koha-community.org/show_bug.cgi?id=15562 >--- > C4/Context.pm | 36 +++++++++++++++++++----------------- > t/db_dependent/sysprefs.t | 12 +++++++++++- > 2 files changed, 30 insertions(+), 18 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index bae5f12..3f94baf 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -370,6 +370,7 @@ sub new { > $self->{"activeuser"} = undef; # current active user > $self->{"shelves"} = undef; > $self->{tz} = undef; # local timezone object >+ $self->{sysprefs} = {}; > > bless $self, $class; > $self->{db_driver} = db_scheme2dbi($self->config('db_scheme')); # cache database driver >@@ -505,7 +506,6 @@ with this method. > =cut > > my $syspref_cache = Koha::Cache->get_instance(); >-my %syspref_L1_cache; > my $use_syspref_cache = 1; > sub preference { > my $self = shift; >@@ -513,10 +513,9 @@ sub preference { > > $var = lc $var; > >- # Return the value if the var has already been accessed >- if ($use_syspref_cache && exists $syspref_L1_cache{$var}) { >- return $syspref_L1_cache{$var}; >- } >+ $self = $context unless ref $self; >+ >+ return $self->{sysprefs}{$var} if $use_syspref_cache && $self && exists $self->{sysprefs}{$var}; > > my $cached_var = $use_syspref_cache > ? $syspref_cache->get_from_cache("syspref_$var") >@@ -526,15 +525,13 @@ sub preference { > my $value; > 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; >+ } elsif ( my $syspref = Koha::Config::SysPrefs->find( $var ) ) { >+ $value = $syspref->value(); > } > > if ( $use_syspref_cache ) { > $syspref_cache->set_in_cache("syspref_$var", $value); >- $syspref_L1_cache{$var} = $value; >+ $self->{sysprefs}{$var} = $value if $self; > } > return $value; > } >@@ -588,13 +585,14 @@ will not be seen by this process. > =cut > > sub clear_syspref_cache { >+ my ($self) = @_; >+ >+ $self = $context unless ref $self; >+ > return unless $use_syspref_cache; >- $syspref_cache->flush_all; >- clear_syspref_L1_cache() >-} > >-sub clear_syspref_L1_cache { >- %syspref_L1_cache = (); >+ $syspref_cache->flush_all; >+ $self->{sysprefs} = {} if $self; > } > > =head2 set_preference >@@ -613,6 +611,8 @@ sub set_preference { > > $variable = lc $variable; > >+ $self = $context unless ref $self; >+ > my $syspref = Koha::Config::SysPrefs->find($variable); > $type = > $type ? $type >@@ -647,7 +647,7 @@ sub set_preference { > > if ( $use_syspref_cache ) { > $syspref_cache->set_in_cache( "syspref_$variable", $value ); >- $syspref_L1_cache{$variable} = $value; >+ $self->{sysprefs}{$variable} = $value if $self; > } > > return $syspref; >@@ -666,10 +666,12 @@ was no syspref of the name. > sub delete_preference { > my ( $self, $var ) = @_; > >+ $self = $context unless ref $self; >+ > if ( Koha::Config::SysPrefs->find( $var )->delete ) { > if ( $use_syspref_cache ) { > $syspref_cache->clear_from_cache("syspref_$var"); >- delete $syspref_L1_cache{$var}; >+ delete $self->{sysprefs}{$var} if $self; > } > > return 1; >diff --git a/t/db_dependent/sysprefs.t b/t/db_dependent/sysprefs.t >index 340e89a..d18a3f1 100755 >--- a/t/db_dependent/sysprefs.t >+++ b/t/db_dependent/sysprefs.t >@@ -19,7 +19,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 8; >+use Test::More tests => 11; > use C4::Context; > > # Start transaction >@@ -60,4 +60,14 @@ is(C4::Context->preference('testpreference'), 'def', 'caching preferences'); > C4::Context->clear_syspref_cache(); > is(C4::Context->preference('testpreference'), undef, 'clearing preference cache'); > >+delete $ENV{OVERRIDE_SYSPREF_opacheader}; >+ >+my $context1 = C4::Context->new(); >+is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"'); >+ >+my $context2 = C4::Context->new(); >+$context2->set_preference( 'opacheader', $newopacheader ); >+is( $context1->preference('opacheader'), $opacheader, 'context1 "opacheader"'); >+is( $context2->preference('opacheader'), $newopacheader, 'context2 "opacheader"'); >+ > $dbh->rollback; >-- >1.9.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 15562
:
47420
|
47421
|
47422
|
47838
|
47944
|
47945
|
47946
|
47947
|
49370
|
49371
|
49372
|
49373
|
49664
|
49665
|
49666
|
49667
|
49709
|
50702
|
50703
|
50713
|
50714
|
50715
|
50716
|
50870
|
51939
|
51940
|
53296
|
53297
|
55577
|
55578
|
60723
|
60724
|
60725
|
60726
|
66374
|
66375
|
66376
|
66377
|
76062