From d8391d0c60759f0128946a329a4bc56809e47593 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 21 Aug 2013 16:57:15 -0400 Subject: [PATCH] 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 --- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 { -- 2.11.0