41 |
41 |
42 def cached_build_user(repo, eid): |
42 def cached_build_user(repo, eid): |
43 """Cached version of |
43 """Cached version of |
44 :meth:`cubicweb.server.repository.Repository._build_user` |
44 :meth:`cubicweb.server.repository.Repository._build_user` |
45 """ |
45 """ |
|
46 if eid in _user_cache: |
|
47 user, lang = _user_cache[eid] |
|
48 entity = clone_user(repo, user) |
|
49 return entity, lang |
|
50 |
46 with repo.internal_cnx() as cnx: |
51 with repo.internal_cnx() as cnx: |
47 if eid in _user_cache: |
|
48 user, lang = _user_cache[eid] |
|
49 entity = clone_user(repo, user) |
|
50 # XXX the cnx is needed here so that the CWUser instance has an |
|
51 # access to the vreg, which it needs when its 'prefered_language' |
|
52 # property is accessed. |
|
53 # If this property did not need a cnx to access a vreg, we could |
|
54 # avoid the internal_cnx() and save more time. |
|
55 cnx_attach_entity(cnx, entity) |
|
56 return entity, lang |
|
57 |
|
58 user = repo._build_user(cnx, eid) |
52 user = repo._build_user(cnx, eid) |
59 lang = user.prefered_language() |
53 lang = user.prefered_language() |
60 user.cw_clear_relation_cache() |
54 user.cw_clear_relation_cache() |
61 _user_cache[eid] = (clone_user(repo, user), lang) |
55 _user_cache[eid] = (clone_user(repo, user), lang) |
62 return user, lang |
56 return user, lang |