Commit 958b993c authored by Vincent Pelletier's avatar Vincent Pelletier

Minor speed improvements:

Rename some variables which had too-generic names.
Use a set instead of a list when used with "in".
Use a set instead of a value-less dict.
Use string slice instead of "tsartswith" method.
Use 'iter...' variations of dictiteration methods.
Use 'itervalues' instead of 'iteritems' + item lookup by key.
Do not check if a role to skip is already present in new role list.
Fetch instance methods just once when called in a loop.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19312 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 48b0cdcd
...@@ -54,6 +54,7 @@ from Products.ERP5Security.ERP5UserManager import SUPER_USER ...@@ -54,6 +54,7 @@ from Products.ERP5Security.ERP5UserManager import SUPER_USER
import os, time, urllib, warnings import os, time, urllib, warnings
import sys import sys
from zLOG import LOG, PROBLEM, WARNING, INFO from zLOG import LOG, PROBLEM, WARNING, INFO
import sets
SECURITY_USING_NUX_USER_GROUPS, SECURITY_USING_PAS = range(2) SECURITY_USING_NUX_USER_GROUPS, SECURITY_USING_PAS = range(2)
try: try:
...@@ -115,11 +116,6 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper): ...@@ -115,11 +116,6 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper):
withnuxgroups = security_product == SECURITY_USING_NUX_USER_GROUPS withnuxgroups = security_product == SECURITY_USING_NUX_USER_GROUPS
withpas = security_product == SECURITY_USING_PAS withpas = security_product == SECURITY_USING_PAS
allowed = {}
for r in rolesForPermissionOn('View', ob):
allowed[r] = 1
if 'Owner' in allowed:
del allowed['Owner']
if withnuxgroups: if withnuxgroups:
localroles = mergedLocalRoles(ob, withgroups=1) localroles = mergedLocalRoles(ob, withgroups=1)
elif withpas: elif withpas:
...@@ -132,35 +128,41 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper): ...@@ -132,35 +128,41 @@ class IndexableObjectWrapper(CMFCoreIndexableObjectWrapper):
# roles acquired on the parent of the parent....] # roles acquired on the parent of the parent....]
# So if we have ['-Author','Author'] we should remove the role 'Author' # So if we have ['-Author','Author'] we should remove the role 'Author'
# but if we have ['Author','-Author'] we have to keep the role 'Author' # but if we have ['Author','-Author'] we have to keep the role 'Author'
new_dict = {} flat_localroles = {}
for key in localroles.keys(): skip_role_set = sets.Set()
new_list = [] skip_role = skip_role_set.add
remove_list = [] clear_skip_role = skip_role_set.clear
for role in localroles[key]: for key, role_list in localroles.iteritems():
if role.startswith('-'): new_role_list = []
if not role[1:] in new_list and not role[1:] in remove_list: new_role = new_role_list.append
remove_list.append(role[1:]) clear_skip_role()
elif not role in remove_list: for role in role_list:
new_list.append(role) if role[:1] == '-':
if len(new_list)>0: skip_role(role[1:])
new_dict[key] = new_list elif role not in skip_role_set:
localroles = new_dict new_role(role)
if len(new_role_list)>0:
flat_localroles[key] = new_role_list
localroles = flat_localroles
# For each local role of a user: # For each local role of a user:
# If the local role grants View permission, add it. # If the local role grants View permission, add it.
# Every addition implies 2 lines: # Every addition implies 2 lines:
# user:<user_id> # user:<user_id>
# user:<user_id>:<role_id> # user:<user_id>:<role_id>
# A line must not be present twice in final result. # A line must not be present twice in final result.
allowed = sets.Set(rolesForPermissionOn('View', ob))
allowed.discard('Owner')
add = allowed.add
for user, roles in localroles.iteritems(): for user, roles in localroles.iteritems():
if withnuxgroups: if withnuxgroups:
prefix = user prefix = user
else: else:
prefix = 'user:' + user prefix = 'user:' + user
for role in roles: for role in roles:
if allowed.has_key(role): if role in allowed:
allowed[prefix] = 1 add(prefix)
allowed[prefix + ':' + role] = 1 add(prefix + ':' + role)
return list(allowed.keys()) return list(allowed)
class RelatedBaseCategory(Method): class RelatedBaseCategory(Method):
"""A Dynamic Method to act as a related key. """A Dynamic Method to act as a related key.
......
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