Commit c70f1f3d authored by Vincent Pelletier's avatar Vincent Pelletier Committed by Kazuhiko Shiozaki

getSecurityUidDictAndRoleColumnDict micro-optimisation

try..except is significantly slower than getattr with default value when
an exception is raised.
defaultdict is faster than calling setdefault.
The two other try..except blocks need more careful analysis of typical
hit-rates to tell if they are optimal.
parent 30ad5114
......@@ -26,6 +26,7 @@
#
##############################################################################
from collections import defaultdict
from Products.CMFCore.CatalogTool import CatalogTool as CMFCoreCatalogTool
from Products.ZSQLCatalog.ZSQLCatalog import ZCatalog
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
......@@ -526,15 +527,10 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
# dtml instead ? ... yes, but how to be bw compatible ?
allowedRolesAndUsers = [sqlquote(role) for role in allowedRolesAndUsers]
security_uid_dict = dict()
security_uid_dict = defaultdict(list)
for brain in method(security_roles_list=allowedRolesAndUsers):
try:
local_roles_group_id = brain.local_roles_group_id
except AttributeError:
# backwards compatability in cases when catalog use default schema
local_roles_group_id = ''
security_uid_dict.setdefault(local_roles_group_id,
[]).append(brain.uid)
security_uid_dict[getattr(brain, 'local_roles_group_id', '')
].append(brain.uid)
security_uid_cache[cache_key] = security_uid_dict
else:
......
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