Commit 77d94dd5 authored by Julien Muchembled's avatar Julien Muchembled

Speed up RuleTool.searchRuleList by quickly filtering out rules

parent 1cea9468
......@@ -30,8 +30,6 @@ from Products.ERP5Type.Tool.BaseTool import BaseTool
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass, DTMLFile
from Products.ERP5Type import Permissions
from Products.CMFCore.utils import getToolByName
from Products.ERP5 import _dtmldir
class RuleTool(BaseTool):
......@@ -96,13 +94,31 @@ class RuleTool(BaseTool):
- the rule must be of a known portal type
- Predicate criterions can be used (like start_date_range_min)
"""
domain_tool = getToolByName(self.getPortalObject(), "portal_domains")
rule_list = domain_tool.searchPredicateList(context=movement,
tested_base_category_list=tested_base_category_list,
portal_type=self.getPortalRuleTypeList(),
validation_state="validated", **kw) #XXX "validated" is hardcoded
portal = self.getPortalObject()
# Most rules are only configured through their test_method_id,
# so filter out them quickly before invoking slow searchPredicateList.
rule_uid_list = []
for rule in portal.portal_catalog.unrestrictedSearchResults(
portal_type=portal.getPortalRuleTypeList(),
validation_state="validated", **kw): #XXX "validated" is hardcoded
rule = rule.getObject()
try:
for test_method_id in rule.getTestMethodIdList():
if test_method_id == 'Rule_testFalse' or \
not getattr(movement, test_method_id)(rule):
break
else:
rule_uid_list.append(rule.getUid())
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())
return rule_uid_list and portal.portal_domains.searchPredicateList(
context=movement, uid=rule_uid_list,
tested_base_category_list=tested_base_category_list)
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