From a7e931cb0481b372b87cb9aba2930053d8baca35 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 13 May 2014 10:37:42 -0400 Subject: [PATCH] cache org setting values for ws_ou Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/staff/services/org.js | 35 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/services/org.js b/Open-ILS/web/js/ui/default/staff/services/org.js index b07c41bc77..8ff71373f6 100644 --- a/Open-ILS/web/js/ui/default/staff/services/org.js +++ b/Open-ILS/web/js/ui/default/staff/services/org.js @@ -11,6 +11,10 @@ function($q, egEnv, egAuth, egNet) { var service = {}; + // org unit settings cache. + // This allows the caller to avoid local caches + service.cachedSettings = {}; + service.get = function(node_or_id) { if (typeof node_or_id == 'object') return node_or_id; @@ -67,6 +71,26 @@ function($q, egEnv, egAuth, egNet) { service.settings = function(names, ou_id) { var deferred = $q.defer(); ou_id = ou_id || egAuth.user().ws_ou(); + var here = (ou_id == egAuth.user().ws_ou()); + + // allow non-array + if (!angular.isArray(names)) names = [names]; + + if (here) { + // only cache org settings retrieved for the current + // workstation org unit. + var newNames = []; + angular.forEach(names, function(name) { + if (!angular.isDefined(service.cachedSettings[name])) + newNames.push(name) + }); + + // only retrieve uncached values + names = newNames; + if (names.length == 0) + return $q.when(service.cachedSettings); + } + egNet.request( 'open-ils.actor', 'open-ils.actor.ou_setting.ancestor_default.batch', @@ -74,11 +98,14 @@ function($q, egEnv, egAuth, egNet) { ).then(function(blob) { var settings = {}; angular.forEach(blob, function(val, key) { - // val is either null or a structure containing - // the value - if (val) { settings[key] = val.value } + // val is either null or a structure containing the value + settings[key] = val ? val.value : null; + if (here) service.cachedSettings[key] = settings[key]; }); - deferred.resolve(settings); + + // resolve with cached settings if 'here', since 'settings' + // will only contain settings we had to retrieve + deferred.resolve(here ? service.cachedSettings : settings); }); return deferred.promise; } -- 2.11.0