[pyramid] No more need for an internal connection when user is cached 3.24
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 10 Nov 2016 18:25:50 +0100
branch3.24
changeset 11827 851b6bd79b50
parent 11826 e2c940c8c485
child 11828 a06cf11f7d87
[pyramid] No more need for an internal connection when user is cached
cubicweb/pyramid/tools.py
--- a/cubicweb/pyramid/tools.py	Thu Nov 10 18:23:45 2016 +0100
+++ b/cubicweb/pyramid/tools.py	Thu Nov 10 18:25:50 2016 +0100
@@ -43,18 +43,12 @@
     """Cached version of
     :meth:`cubicweb.server.repository.Repository._build_user`
     """
+    if eid in _user_cache:
+        user, lang = _user_cache[eid]
+        entity = clone_user(repo, user)
+        return entity, lang
+
     with repo.internal_cnx() as cnx:
-        if eid in _user_cache:
-            user, lang = _user_cache[eid]
-            entity = clone_user(repo, user)
-            # XXX the cnx is needed here so that the CWUser instance has an
-            # access to the vreg, which it needs when its 'prefered_language'
-            # property is accessed.
-            # If this property did not need a cnx to access a vreg, we could
-            # avoid the internal_cnx() and save more time.
-            cnx_attach_entity(cnx, entity)
-            return entity, lang
-
         user = repo._build_user(cnx, eid)
         lang = user.prefered_language()
         user.cw_clear_relation_cache()