Bugzilla – Attachment 109827 Details for
Bug 26393
Add cache on Koha::CirculationRules::get_effective_rule
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26393: Add cache on Koha::CirculationRules::get_effective_rule
Bug-26393-Add-cache-on-KohaCirculationRulesgeteffe.patch (text/plain), 2.48 KB, created by
Fridolin Somers
on 2020-09-09 14:46:53 UTC
(
hide
)
Description:
Bug 26393: Add cache on Koha::CirculationRules::get_effective_rule
Filename:
MIME Type:
Creator:
Fridolin Somers
Created:
2020-09-09 14:46:53 UTC
Size:
2.48 KB
patch
obsolete
>From f41d6974baf0e17af5f044f56c421d717aee037e Mon Sep 17 00:00:00 2001 >From: Fridolin Somers <fridolin.somers@biblibre.com> >Date: Fri, 4 Sep 2020 17:25:24 +0200 >Subject: [PATCH] Bug 26393: Add cache on > Koha::CirculationRules::get_effective_rule > >For performance of several circulation pages we should cache the result of method Koha::CirculationRules::get_effective_rule. > >Adds a constant CACHE_NO_CIRCULATION_RULE_VALUE to store a special >value when method must return undef. >--- > Koha/CirculationRules.pm | 19 +++++++++++++++++++ > admin/smart-rules.pl | 1 + > 2 files changed, 20 insertions(+) > >diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm >index 87062f541a..9e7d79880f 100644 >--- a/Koha/CirculationRules.pm >+++ b/Koha/CirculationRules.pm >@@ -26,6 +26,8 @@ use Koha::CirculationRule; > use base qw(Koha::Objects); > > use constant GUESSED_ITEMTYPES_KEY => 'Koha_IssuingRules_last_guess'; >+use constant EFFECTIVE_RULE_KEY => 'Koha_CirculationRule_get_effective_rule-'; >+use constant CACHE_NO_CIRCULATION_RULE_VALUE => 'NONE'; > > =head1 NAME > >@@ -190,6 +192,21 @@ sub get_effective_rule { > "Required parameter 'rule_name' missing") > unless $rule_name; > >+ my $cache = Koha::Caches->get_instance(); >+ my $cache_key = EFFECTIVE_RULE_KEY.$rule_name; >+ foreach ( $branchcode, $categorycode, $itemtype ) { >+ $cache_key .= '-'.($_ ? $_ : ''); >+ } >+ my $cached = $cache->get_from_cache($cache_key); >+ if ($cached) { >+ if ( ref $cached eq 'SCALAR' && $cached eq CACHE_NO_CIRCULATION_RULE_VALUE ) { >+ return undef; >+ } >+ my $cr = Koha::CirculationRule->new($cached); >+ $cr->{_result}->in_storage(1); # Tell it exists in DB >+ return $cr; >+ } >+ > for my $v ( $branchcode, $categorycode, $itemtype ) { > $v = undef if $v and $v eq '*'; > } >@@ -212,6 +229,8 @@ sub get_effective_rule { > } > )->single; > >+ $cache->set_in_cache( $cache_key, $rule ? $rule->unblessed : CACHE_NO_CIRCULATION_RULE_VALUE ); >+ > return $rule; > } > >diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl >index 4a4727e5c2..f33eda763a 100755 >--- a/admin/smart-rules.pl >+++ b/admin/smart-rules.pl >@@ -69,6 +69,7 @@ my $language = C4::Languages::getlanguage(); > > my $cache = Koha::Caches->get_instance; > $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); >+$cache->clear_from_cache( Koha::CirculationRules::EFFECTIVE_RULE_KEY ); > > if ($op eq 'delete') { > my $itemtype = $input->param('itemtype'); >-- >2.27.0
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 26393
:
109670
|
109827
|
109839
|
109840
|
109846