Commit 7d3031bb authored by 's avatar

Added careful caching to getRolesInContext, which is an expensive op

that requires climbing the entire aq chain on every call (and it gets
called a *lot*). A little investigation revealed that it is called
over and over for the same objects during a request for complex pages,
so a cache was added that can cut the work down to about 10% of its
current level.
parent 42c1ff95
......@@ -84,7 +84,7 @@
##############################################################################
"""Access control package"""
__version__='$Revision: 1.88 $'[11:-2]
__version__='$Revision: 1.89 $'[11:-2]
import Globals, App.Undo, socket, regex
from Globals import HTMLFile, MessageDialog, Persistent, PersistentMapping
......@@ -131,6 +131,15 @@ class BasicUser(Implicit):
including local roles assigned in context of
the passed in object."""
name=self.getUserName()
robj=self.REQUEST
# in-line caching
key='%s_%s' % (name, id(object))
rc=getattr(robj, '_rc__', {})
roles=rc.get(key, None)
if roles is not None:
return roles
roles=self.getRoles()
local={}
while 1:
......@@ -145,8 +154,13 @@ class BasicUser(Implicit):
object=object.im_self
continue
break
joined=rolejoin(roles, local.keys())
return joined
roles=list(roles) + local.keys()
# in-line caching
if not hasattr(robj, '_rc__'):
robj._rc__={}
robj._rc__[key]=roles
return roles
def getDomains(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment