From: Bill Erickson Date: Wed, 21 Aug 2013 20:57:15 +0000 (-0400) Subject: TPAC cache copy location groups X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fberick%2Ftpac-cache-copy-loc-groups;p=working%2FEvergreen.git TPAC cache copy location groups Like other similary types of data, which are loaded on every page load, cache copies of the copy location groups (by locale and org unit context) in a process-local cache to speed up page loads and reduce DB calls. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 6382210670..247ecc86bb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -4,6 +4,7 @@ use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERR use File::Spec; use Time::HiRes qw/time sleep/; use OpenSRF::Utils::Cache; +use OpenSRF::Utils::JSON; use OpenSRF::Utils::Logger qw/$logger/; use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Fieldmapper; @@ -22,7 +23,8 @@ our %cache = ( # cached data aou_tree => {en_us => undef}, aouct_tree => {}, eg_cache_hash => undef, - authority_fields => {en_us => {}} + authority_fields => {en_us => {}}, + copy_location_groups => {en_us => {}} ); sub init_ro_object_cache { @@ -565,6 +567,12 @@ sub load_copy_location_groups { push(@ctx_orgs, $ctx->{physical_loc}) if $ctx->{physical_loc}; push(@ctx_orgs, $ctx->{user}->home_ou) if $ctx->{user}; + @ctx_orgs = sort(keys %{{ map {$_ => 1} @ctx_orgs}}); # sort/uniq + my $cache_key = OpenSRF::Utils::JSON->perl2JSON(\@ctx_orgs); + + return $cache{copy_location_groups}{$ctx->{locale}}{$cache_key} + if $cache{copy_location_groups}{$ctx->{locale}}{$cache_key}; + my $grps = $self->editor->search_asset_copy_location_group([ { opac_visible => 't', @@ -585,7 +593,10 @@ sub load_copy_location_groups { my %buckets; push(@{$buckets{$_->owner}}, $_) for @$grps; - $ctx->{copy_location_groups} = \%buckets; + + $ctx->{copy_location_groups} = + $cache{copy_location_groups}{$ctx->{locale}}{$cache_key} = + \%buckets; } sub set_file_download_headers {