You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/06/13 20:34:59 UTC

[17/17] git commit: [#7406] add caching to FieldPropertyDisplayName to help non-local pref cases

[#7406] add caching to FieldPropertyDisplayName to help non-local pref cases


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/dceba9ef
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/dceba9ef
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/dceba9ef

Branch: refs/heads/db/7406
Commit: dceba9ef56fc15fdc41d45baa5716034b0e0fcda
Parents: b5e37f6
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Thu Jun 12 21:55:10 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Jun 13 17:52:00 2014 +0000

----------------------------------------------------------------------
 Allura/allura/model/auth.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/dceba9ef/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 028e9dd..17f1175 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -199,11 +199,17 @@ class AuthGlobals(MappedClass):
 class FieldPropertyDisplayName(FieldProperty):
     # display_name is mongo field but only for preference storage
     # force all requests for this field to use the get_pref mechanism
+    # Cache it per user, since it may be re-used several times in a request
+    # and non-local preferences (ldap, database, etc) can be relatively expensive
 
     def __get__(self, instance, cls=None):
         if instance is None:
             return self
-        return instance.get_pref('display_name')
+        try:
+            display_name = instance._cache_display_name
+        except AttributeError:
+            display_name = instance._cache_display_name = instance.get_pref('display_name')
+        return display_name
 
 
 class User(MappedClass, ActivityNode, ActivityObject):