From: berick Date: Wed, 20 Apr 2011 15:00:22 +0000 (-0400) Subject: added simple field/value filter to the RO fetch/cache code; useful for limiting... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=456941876b589c3c29f200433f1aedd7b74565d3;p=evergreen%2Fequinox.git added simple field/value filter to the RO fetch/cache code; useful for limiting larger sets of config data like ccvm objects --- 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 282d0e1cc6..8b12453e70 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -12,6 +12,7 @@ my $ro_object_subs; # cached subs our %cache = ( # cached data map => {aou => {}}, # others added dynamically as needed list => {}, + search => {}, org_settings => {} ); @@ -42,21 +43,34 @@ sub init_ro_object_cache { my $list_key = "${hint}_list"; my $get_key = "get_$hint"; + my $search_key = "search_$hint"; + # Retrieve the full set of objects with class $hint $ro_object_subs->{$list_key} = sub { my $method = "retrieve_all_$eclass"; $cache{list}{$hint} = $e->$method() unless $cache{list}{$hint}; return $cache{list}{$hint}; }; - $cache{map}{$hint} = {} unless $cache{map}{$hint}; - + # locate object of class $hint with Ident field $id + $cache{map}{$hint} = {}; $ro_object_subs->{$get_key} = sub { my $id = shift; return $cache{map}{$hint}{$id} if $cache{map}{$hint}{$id}; ($cache{map}{$hint}{$id}) = grep { $_->$ident_field eq $id } @{$ro_object_subs->{$list_key}->()}; return $cache{map}{$hint}{$id}; }; + + # search for objects of class $hint where field=value + $cache{search}{$hint} = {}; + $ro_object_subs->{$search_key} = sub { + my ($field, $val) = @_; + my $method = "search_$eclass"; + $cache{search}{$hint}{$field} = {} unless $cache{search}{$hint}{$field}; + $cache{search}{$hint}{$field}{$val} = $e->$method({$field => $val}) + unless $cache{search}{$hint}{$field}{$val}; + return $cache{search}{$hint}{$field}{$val}; + }; } $ro_object_subs->{aou_tree} = sub {