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/19 17:53:16 UTC

[8/9] 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/21b5001c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/21b5001c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/21b5001c

Branch: refs/heads/master
Commit: 21b5001c5122c38f29b8e6937237fbf50cc1792f
Parents: 10da9e6
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Thu Jun 12 21:55:10 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Jun 19 15:52:51 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/21b5001c/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):