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