From 730bbcb1903264881d553a75b6af10b86e5952ce Mon Sep 17 00:00:00 2001 From: Yoshinori Okuji <yo@nexedi.com> Date: Wed, 11 Aug 2010 10:02:22 +0000 Subject: [PATCH] Skip reindexing Applied Rules unnecessarily when expanding simulation. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37691 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/AppliedRule.py | 53 ++++++++++++++++++++++++++++ product/ERP5/Document/Delivery.py | 6 ++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/product/ERP5/Document/AppliedRule.py b/product/ERP5/Document/AppliedRule.py index 6ddaffeaf3..359cddc832 100644 --- a/product/ERP5/Document/AppliedRule.py +++ b/product/ERP5/Document/AppliedRule.py @@ -275,3 +275,56 @@ class AppliedRule(XMLObject): Return a list of movements. """ return self.objectValues(portal_type=Rule.movement_type) + + security.declareProtected(Permissions.AccessContentsInformation, + 'getIndexableChildSimulationMovementValueList') + def getIndexableChildSimulationMovementValueList(self): + return [x for x in self.getIndexableChildValueList() + if x.getPortalType() == 'Simulation Movement'] + + security.declarePublic('recursiveImmediateReindexSimulationMovement') + def recursiveImmediateReindexSimulationMovement(self, **kw): + """ + Applies immediateReindexObject recursively to Simulation Movements + """ + # Reindex direct children + root_indexable = int(getattr(self.getPortalObject(), 'isIndexable', 1)) + for movement in self.objectValues(): + if movement.isIndexable and root_indexable: + movement.immediateReindexObject(**kw) + # Go recursively + for movement in self.objectValues(): + for applied_rule in movement.objectValues(): + applied_rule.recursiveImmediateReindexSimulationMovement(**kw) + + security.declarePublic('recursiveReindexObject') + def recursiveReindexSimulationMovement(self, activate_kw=None, **kw): + if self.isIndexable: + if activate_kw is None: + activate_kw = {} + + reindex_kw = self.getDefaultReindexParameterDict() + if reindex_kw is not None: + reindex_activate_kw = reindex_kw.pop('activate_kw', None) + if reindex_activate_kw is not None: + reindex_activate_kw = reindex_activate_kw.copy() + if activate_kw is not None: + # activate_kw parameter takes precedence + reindex_activate_kw.update(activate_kw) + activate_kw = reindex_activate_kw + kw.update(reindex_kw) + + group_id_list = [] + if kw.get("group_id", "") not in ('', None): + group_id_list.append(kw.get("group_id", "")) + if kw.get("sql_catalog_id", "") not in ('', None): + group_id_list.append(kw.get("sql_catalog_id", "")) + group_id = ' '.join(group_id_list) + + self.activate(group_method_id='portal_catalog/catalogObjectList', + expand_method_id='getIndexableChildSimulationMovementValueList', + alternate_method_id='alternateReindexObject', + group_id=group_id, + serialization_tag=self.getRootDocumentPath(), + **activate_kw).recursiveImmediateReindexSimulationMovement(**kw) + diff --git a/product/ERP5/Document/Delivery.py b/product/ERP5/Document/Delivery.py index 960d283869..6ff0763285 100644 --- a/product/ERP5/Document/Delivery.py +++ b/product/ERP5/Document/Delivery.py @@ -801,7 +801,7 @@ class Delivery(XMLObject, ImmobilisationDelivery, CompositionMixin): # indexing. The only exception is the simulation state. # I think, if each simulation movement remembers the previous # state, we can avoid unnecessary reindexing. - my_applied_rule.recursiveReindexObject(activate_kw=activate_kw) + my_applied_rule.recursiveReindexSimulationMovement(activate_kw=activate_kw) else: LOG("ERP5", PROBLEM, "Could not expand applied rule %s for delivery %s" %\ @@ -836,8 +836,8 @@ class Delivery(XMLObject, ImmobilisationDelivery, CompositionMixin): if parent_value not in to_expand_list: to_expand_list.append(parent_value) for rule in to_expand_list: - rule.expand(activate_kw=activate_kw,**kw) - rule.recursiveReindexObject(activate_kw=activate_kw) + rule.expand(activate_kw=activate_kw, **kw) + rule.recursiveReindexSimulationMovement(activate_kw=activate_kw) security.declareProtected( Permissions.AccessContentsInformation, 'getRootCausalityValueList') -- 2.30.9