[entities] Optimize CWUser.properties.
authorChristophe de Vienne <christophe@unlish.com>
Sat, 03 Jan 2015 04:06:06 +0100
changeset 10141 62e1f9749d3a
parent 10140 e14ec2aac099
child 10142 f4a4556f23da
[entities] Optimize CWUser.properties. This property gets called each time a user connects to a repository, which means a lot. This optimisation cuts its execution time by 5 according to my tests
entities/authobjs.py
--- a/entities/authobjs.py	Tue Mar 04 12:41:21 2014 +0100
+++ b/entities/authobjs.py	Sat Jan 03 04:06:06 2015 +0100
@@ -74,7 +74,11 @@
         try:
             return self._properties
         except AttributeError:
-            self._properties = dict((p.pkey, p.value) for p in self.reverse_for_user)
+            self._properties = dict(
+                self._cw.execute(
+                    'Any K, V WHERE P for_user U, U eid %(userid)s, '
+                    'P pkey K, P value V',
+                    {'userid': self.eid}))
             return self._properties
 
     def prefered_language(self, language=None):