diff -r d4fbfc6a7662 roundup/security.py --- a/roundup/security.py Tue Oct 01 23:52:04 2024 -0400 +++ b/roundup/security.py Thu Oct 17 09:53:25 2024 -0400 @@ -9,6 +9,29 @@ import logging logger = logging.getLogger('roundup.security') +def memoize_hasPermission(p): + cache = {} + + def inner(s, permission, userid, classname=None, property=None, itemid=None): + '''only cache simple calls permission/username/classname? + if prop or itemid defined pass don't lookup + ''' + if property or itemid: + logger.error('in cache: calling no memoize, %s', + (permission, userid, classname, property, itemid)) + return p(s, permission, userid, classname, property, itemid) + + if (permission, userid, classname) in cache: + logger.error('in cache: returning memoize, %s', + (permission, userid, classname)) + return cache[(permission, userid, classname)] + + r = p(s, permission, userid, classname, property, itemid) + cache[(permission, userid, classname)] = r + logger.error('in cache: memoized %s', (permission, userid, classname)) + return r + + return inner class Permission: ''' Defines a Permission with the attributes @@ -248,6 +271,7 @@ raise ValueError('No permission "%s" defined for "%s"' % (permission, classname)) + @memoize_hasPermission def hasPermission(self, permission, userid, classname=None, property=None, itemid=None): '''Look through all the Roles, and hence Permissions, and