Commit ed0c06f9 authored by Vincent Pelletier's avatar Vincent Pelletier

CatalogTool: Avoid computing user's roles when just testing existence.

Global role computation is very expensive, don't do it when all we are
interested in is user existence.
Also, list all users having local roles in one call to reduce the effect
of per-call overhead.
This should improve indexation speed by a large fraction: pprofile
statistical run on and activity node busy reindexing objects shows:
- 57% of time spend generating (13%) and executing (44%) SQL
- 42% of time spent preparing object for indexation:
  - 29% in _getSecurityParameterList, all in getUserById
  - 12% in getCatalogVariablesFor (workflow variables to index)
So an improvement of close to 30% is expected.
parent 6be1d3a1
......@@ -98,13 +98,27 @@ class IndexableObjectWrapper(object):
skip_role(role[1:])
elif role not in skip_role_set:
new_role(role)
if len(new_role_list)>0:
localroles[key] = new_role_list
if new_role_list:
localroles[key] = [new_role_list, False]
portal = ob.getPortalObject()
role_dict = dict(portal.portal_catalog.getSQLCatalog().\
getSQLCatalogRoleKeysList())
getUserById = portal.acl_users.getUserById
for user_info in portal.acl_users.searchUsers(id=tuple(localroles), exact_match=True):
key = user_info['id']
try:
localroles[key][1] = True
except KeyError:
# We found a bug, report it but do not make indexation fail.
LOG(
'CatalogTool.IndexableObjectWrapper',
PROBLEM,
'searchUser(id=%r, exact_match=True) returned an entry with '
'id=%r. This is very likely a bugin a PAS plugin !' % (
tuple(localroles),
key,
),
)
allowed_dict = {}
......@@ -161,8 +175,7 @@ class IndexableObjectWrapper(object):
optimized_role_set.add((user, role))
# Then parse other roles
for user, roles in localroles.iteritems():
user_exists = getUserById(user) is not None
for user, (roles, user_exists) in localroles.iteritems():
prefix = 'user:' + user
for role in roles:
if user_exists and role in role_dict:
......
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