[open-ils-commits] r12569 - in trunk/Open-ILS/web/js/dojo/openils: . widget (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Mar 17 22:31:16 EDT 2009


Author: erickson
Date: 2009-03-17 22:31:15 -0400 (Tue, 17 Mar 2009)
New Revision: 12569

Modified:
   trunk/Open-ILS/web/js/dojo/openils/User.js
   trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
Log:
added some user sesssion and object-list caching

Modified: trunk/Open-ILS/web/js/dojo/openils/User.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/User.js	2009-03-17 22:10:28 UTC (rev 12568)
+++ trunk/Open-ILS/web/js/dojo/openils/User.js	2009-03-18 02:31:15 UTC (rev 12569)
@@ -35,6 +35,8 @@
         authtoken : null,
         authtime : null,
         workstation : null,
+        permOrgCache : {},
+        sessionCache : {},
     
         constructor : function ( kwargs ) {
             kwargs = kwargs || {};
@@ -51,6 +53,10 @@
             if (this.id && this.authtoken) this.user = this.getById( this.id );
             else if (this.authtoken) this.getBySession();
             else if (kwargs.login) this.login();
+
+            var id = this.id || (this.user) ? this.user.id() : null;
+            if(id && !this.permOrgCache[id])
+                this.permOrgCache[id] = {};
         },
 
         getBySession : function(onComplete) {
@@ -58,6 +64,13 @@
             var req = ['open-ils.auth', 'open-ils.auth.session.retrieve'];
             var params = [_u.authtoken];
 
+            if(this.sessionCache[this.authtoken]) {
+                this.user = this.sessionCache[this.authtoken];
+				if (!openils.User.user) 
+                    openils.User.user = this.user;
+                return this.user;
+            }
+
             if(onComplete) {
                 fieldmapper.standardRequest(
                     req, {   
@@ -66,6 +79,7 @@
                         oncomplete : function(r) {
                             var user = r.recv().content();
                             _u.user = user;
+                            _u.sessionCache[_u.authtoken] = user;
 					        if (!openils.User.user) openils.User.user = _u.user;
                             if(onComplete)
                                 onComplete(user);
@@ -75,6 +89,7 @@
             } else {
                 _u.user = fieldmapper.standardRequest(req, params);
 				if (!openils.User.user) openils.User.user = _u.user;
+                _u.sessionCache[_u.authtoken] = _u.user;
                 return _u.user;
             }
         },
@@ -185,12 +200,15 @@
         getPermOrgList : function(permList, onload, includeDescendents, idlist) {
             if(typeof permList == 'string') permList = [permList];
 
-            console.log('loading org perms ' + permList + ' for user ' + this.user.id());
+            var self = this;
             var oncomplete = function(r) {
-                var permMap = openils.Util.readResponse(r);
+                var permMap = {};
+                if(r) permMap = openils.Util.readResponse(r);
                 var orgList = [];
-                for(var perm in permMap) {
-                    var permOrgList = permMap[perm];
+                for(var i = 0; i < permList.length; i++) {
+                    var perm = permList[i];
+                    var permOrgList = permMap[perm] || self.permOrgCache[self.user.id()][perm];
+                    self.permOrgCache[self.user.id()][perm] = permOrgList;
                     for(var i in permOrgList) {
                         if(includeDescendents) {
                             orgList = orgList.concat(
@@ -211,10 +229,19 @@
                 onload(trimmed);
             };
 
+            var fetchList = [];
+            for(var i = 0; i < permList.length; i++) {
+                if(!self.permOrgCache[self.user.id()][permList[i]])
+                    fetchList.push(permList[i]);
+            }
+
+            if(fetchList.length == 0) 
+                return oncomplete();
+
             fieldmapper.standardRequest(
                 ['open-ils.actor', 'open-ils.actor.user.has_work_perm_at.batch'],
                 {   async: true,
-                    params: [this.authtoken, permList],
+                    params: [this.authtoken, fetchList],
                     oncomplete: oncomplete
                 }
             );

Modified: trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2009-03-17 22:10:28 UTC (rev 12568)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2009-03-18 02:31:15 UTC (rev 12569)
@@ -203,19 +203,29 @@
             this.widget.searchAttr = this.widget.labelAttr = vfield.selector || vfield.name;
             this.widget.valueAttr = vfield.name;
 
-            new openils.PermaCrud().retrieveAll(linkClass, {   
-                async : true,
-                oncomplete : function(r) {
-                    var list = openils.Util.readResponse(r, false, true);
-                    if(list) {
-                        self.widget.store = 
-                            new dojo.data.ItemFileReadStore({data:fieldmapper[linkClass].toStoreData(list)});
-                    }
-                    self.widget.startup();
-                    self._widgetLoaded();
+            var oncomplete = function(list) {
+                if(list) {
+                    self.widget.store = 
+                        new dojo.data.ItemFileReadStore({data:fieldmapper[linkClass].toStoreData(list)});
+                    self.cache[linkClass] = list;
                 }
-            });
+                self.widget.startup();
+                self._widgetLoaded();
+            };
 
+            if(this.cache[linkClass]) {
+                oncomplete(this.cache[linkClass]);
+
+            } else {
+                new openils.PermaCrud().retrieveAll(linkClass, {   
+                    async : true,
+                    oncomplete : function(r) {
+                        var list = openils.Util.readResponse(r, false, true);
+                        oncomplete(list);
+                    }
+                });
+            }
+
             return true;
         },
 



More information about the open-ils-commits mailing list