Bugzilla – Attachment 31726 Details for
Bug 9967
Authorized values are not Plack-compatible
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9967 - Cache authorised value requests properly
Bug-9967---Cache-authorised-value-requests-properl.patch (text/plain), 3.54 KB, created by
Brendan Gallagher
on 2014-09-18 19:12:53 UTC
(
hide
)
Description:
Bug 9967 - Cache authorised value requests properly
Filename:
MIME Type:
Creator:
Brendan Gallagher
Created:
2014-09-18 19:12:53 UTC
Size:
3.54 KB
patch
obsolete
>From efda596febdeaa5c5aab5277facd7a0bd125dee9 Mon Sep 17 00:00:00 2001 >From: Robin Sheat <robin@catalyst.net.nz> >Date: Wed, 9 Apr 2014 15:50:37 +1200 >Subject: [PATCH] Bug 9967 - Cache authorised value requests properly > >Authorised values are now cached using the proper Koha::Cache mechanism, >rather than a simple internal cache. Memoize has been removed because it >didn't really work like we needed it to. > >Test plan: > * running a persistent environment: > * load the edit item screen > * refresh several times to ensure any process-based caches are filled > * add a new LOC authorised value as fast as possible (prepare it on > another tab.) > * refresh the edit item page > * note that the new LOC value may or may not be showing in the > "shelving location" > * if more than 5 seconds have passed since saving it, it must now show > up. > * refresh a few times to ensure that it's showing on all processes. > >Note: > * This patch depends on the caching changes of 9967. > >Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com> >--- > C4/Koha.pm | 32 +++++++++++++++++++++++++++----- > 1 file changed, 27 insertions(+), 5 deletions(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index 6f98ac6..42da37b 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -25,8 +25,8 @@ use strict; > > use C4::Context; > use C4::Branch qw(GetBranchesCount); >+use Koha::Cache; > use Koha::DateUtils qw(dt_from_string); >-use Memoize; > use DateTime::Format::MySQL; > use Business::ISBN; > use autouse 'Data::Dumper' => qw(Dumper); >@@ -82,9 +82,6 @@ BEGIN { > @EXPORT_OK = qw( GetDailyQuote ); > } > >-# expensive functions >-memoize('GetAuthorisedValues'); >- > =head1 NAME > > C4::Koha - Perl Module containing convenience functions for Koha scripts >@@ -1071,13 +1068,33 @@ This function returns all authorised values from the'authorised_value' table in > > C<$category> returns authorised values for just one category (optional). > >+C<$selected> adds a "selected => 1" entry to the hash if the >+authorised_value matches it. B<NOTE:> this feature should be considered >+deprecated as it may be removed in the future. >+ > C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist. > > =cut > > sub GetAuthorisedValues { > my ( $category, $selected, $opac ) = @_; >- my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; >+ >+ # TODO: the "selected" feature should be replaced by a utility function >+ # somewhere else, it doesn't belong in here. For starters it makes >+ # caching much more complicated. Or just let the UI logic handle it, it's >+ # what it's for. >+ >+ # Is this cached already? >+ $opac = $opac ? 1 : 0; # normalise to be safe >+ my $selected_key = defined($selected) ? $selected : ''; >+ my $cache_key = "AuthorisedValues-$category-$selected_key-$opac"; >+ my $cache = Koha::Cache->get_instance(); >+ my $result = $cache->get_from_cache($cache_key); >+warn "fetched $result from cache"; >+ return $result if $result; >+ >+ my $branch_limit = >+ C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; > my @results; > my $dbh = C4::Context->dbh; > my $query = qq{ >@@ -1123,6 +1140,11 @@ sub GetAuthorisedValues { > push @results, $data; > } > $sth->finish; >+ >+ # We can't cache for long because of that "selected" thing which >+ # makes it impossible to clear the cache without iterating through every >+ # value, which sucks. This'll cover this request, and not a whole lot more. >+ $cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } ); > return \@results; > } > >-- >1.7.10.4
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 9967
:
26786
|
26910
|
27383
|
28412
|
28625
|
31726
|
32086
|
32087