Bugzilla – Attachment 47944 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), 3.81 KB, created by
Srdjan Jankovic
on 2016-02-12 04:57:34 UTC
(
hide
)
Description:
bug_15562: Sysprefs cache is object property now
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2016-02-12 04:57:34 UTC
Size:
3.81 KB
patch
obsolete
>From bc786a23ca4c79dd2bd4c1458cb69f11182a0370 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 | 29 ++++++++++++++++------------- > t/db_dependent/sysprefs.t | 14 +++++++++++++- > 2 files changed, 29 insertions(+), 14 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 341438a..1dcdce4 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -368,6 +368,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,29 +506,27 @@ with this method. > # FIXME: running this under mod_perl will require a means of > # flushing the caching mechanism. > >-my %sysprefs; > my $use_syspref_cache = 1; > > sub preference { > my $self = shift; > my $var = shift; # The system preference to return >+ my $lc_var = lc $var; > >- if ($use_syspref_cache && exists $sysprefs{lc $var}) { >- return $sysprefs{lc $var}; >- } >+ $self = $context unless ref $self; >+ >+ return $self->{sysprefs}{$lc_var} if $use_syspref_cache && $self && exists $self->{sysprefs}{$lc_var}; > > my $dbh = C4::Context->dbh or return 0; > > 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( $lc_var ) ) { >+ $value = $syspref->value(); > } > >- $sysprefs{lc $var} = $value; >+ $self->{sysprefs}{$lc_var} = $value if $use_syspref_cache && $self; > return $value; > } > >@@ -578,7 +577,11 @@ will not be seen by this process. > =cut > > sub clear_syspref_cache { >- %sysprefs = (); >+ my ($self) = @_; >+ >+ $self = $context unless ref $self; >+ >+ $self->{sysprefs} = {} if $self; > } > > =head2 set_preference >@@ -595,6 +598,8 @@ sub set_preference { > my $var = lc(shift); > my $value = shift; > >+ $self = $context unless ref $self; >+ > my $syspref = Koha::Config::SysPrefs->find( $var ); > my $type = $syspref ? $syspref->type() : undef; > >@@ -612,9 +617,7 @@ sub set_preference { > $syspref = Koha::Config::SysPref->new( { variable => $var, value => $value } )->store(); > } > >- if ($syspref) { >- $sysprefs{$var} = $value; >- } >+ $self->{sysprefs}{$var} = $value if $use_syspref_cache && $self; > } > > =head2 Zconn >diff --git a/t/db_dependent/sysprefs.t b/t/db_dependent/sysprefs.t >index c678d24..f24390c 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 => 5; >+use Test::More tests => 8; > use C4::Context; > > # Start transaction >@@ -48,3 +48,15 @@ is( C4::Context->preference('IDoNotExist'), undef, 'Get a non-existent system pr > > C4::Context->set_preference( 'IDoNotExist', 'NonExistent' ); > is( C4::Context->preference('IDoNotExist'), 'NonExistent', 'Test creation of non-existent system preference' ); >+ >+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