experiment w/ caching org tree in sessionstorage
authorBill Erickson <berick@esilibrary.com>
Thu, 5 Jun 2014 14:24:17 +0000 (10:24 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 5 Jun 2014 14:24:17 +0000 (10:24 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/services/env.js

index 9860477..ca1d709 100644 (file)
@@ -33,8 +33,8 @@ angular.module('egCoreMod')
 
 // env fetcher
 .factory('egEnv', 
-       ['$q','egAuth','egPCRUD','egIDL',
-function($q,  egAuth,  egPCRUD,  egIDL) { 
+       ['$q','$window','egAuth','egPCRUD','egIDL',
+function($q,  $window , egAuth,  egPCRUD,  egIDL) { 
 
     var service = {
         // collection of custom loader functions
@@ -97,10 +97,26 @@ function($q,  egAuth,  egPCRUD,  egIDL) {
      */
     service.classLoaders = {
         aou : function() {
+
+            // EXPERIMENT: cache the org tree in session storage.
+            // This means that if the org tree changes, users will have to
+            // open the client in a new browser tab to clear the cached tree.
+            var treeJSON = $window.sessionStorage.getItem('eg.env.aou.tree');
+            if (treeJSON) {
+                console.debug('serving org tree from cache');
+                var tree = JSON2js(treeJSON);
+                service.absorbTree(tree, 'aou')
+                return $q.when(tree);
+            }
+
             return egPCRUD.search('aou', {parent_ou : null}, 
                 {flesh : -1, flesh_fields : {aou : ['children', 'ou_type']}}
             ).then(
-                function(tree) {service.absorbTree(tree, 'aou')}
+                function(tree) {
+                    $window.sessionStorage.setItem(
+                        'eg.env.aou.tree', js2JSON(tree));
+                    service.absorbTree(tree, 'aou')
+                }
             );
         },
     };