Commit 3365eecf authored by Julien Muchembled's avatar Julien Muchembled

Stop using Domain Tool to get list of applicable rules, to speed up 'expand'

parent 7e0a0fbb
No related merge requests found
......@@ -95,12 +95,25 @@ class RuleTool(BaseTool):
- Predicate criterions can be used (like start_date_range_min)
"""
portal = self.getPortalObject()
# XXX: For performance reasons, current implementation does not use
# DomainTool._searchPredicateList anymore, because in most cases, it
# does not filter anything before actualling calling Predicate.test()
# Properties must be added on rules to minimize the number of test
# scripts/expressions, like the portal types of the possible parent
# applied rules, so that filtering can be done via the catalog.
# Then it would be possible to use Domain Tool again.
#return portal.domain_tool._searchPredicateList(context=movement,
# tested_base_category_list=tested_base_category_list,
# portal_type=portal.getPortalRuleTypeList(),
# validation_state="validated", **kw) #XXX "validated" is hardcoded
# Most rules are only configured through their test_method_id,
# so filter out them quickly before invoking slow searchPredicateList.
rule_uid_list = []
# so filter out them quickly before calling Predicate.test()
rule_list = []
for rule in portal.portal_catalog.unrestrictedSearchResults(
portal_type=portal.getPortalRuleTypeList(),
validation_state="validated"): #XXX "validated" is hardcoded
validation_state="validated", **kw): #XXX "validated" is hardcoded
rule = rule.getObject()
try:
for test_method_id in rule.getTestMethodIdList():
......@@ -108,17 +121,19 @@ class RuleTool(BaseTool):
not getattr(movement, test_method_id)(rule):
break
else:
rule_uid_list.append(rule.getUid())
if rule.test(movement,
tested_base_category_list=tested_base_category_list):
rule_list.append(rule)
except Exception:
# Maybe the script is old (= it takes no argument). Or we should not
# have called it (= rule would have been excluded before, depending
# on other criterions). Or there may be a bug.
# We don't know why it failed so let searchPredicateList do the work.
rule_uid_list.append(rule.getUid())
# We don't know why it failed so let Predicate.test() do the work.
if rule.test(movement,
tested_base_category_list=tested_base_category_list):
rule_list.append(rule)
return rule_uid_list and portal.portal_domains._searchPredicateList(
context=movement, uid=rule_uid_list,
tested_base_category_list=tested_base_category_list, **kw)
return rule_list
InitializeClass(RuleTool)
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