Commit 57aa77fa authored by Arnaud Fontaine's avatar Arnaud Fontaine

BusinessTemplate: Speedup bt5 install by getting rid of useless resets of ZODB Components.

Until now, a reset was performed even though ZODB Components were not created or
replaced. Introduce a new installation hook to avoid those useless resets.

When installing bootstrap bt5s, erp5_base, erp5_simulation: 33 => 12 resets.
parent 57dd6126
...@@ -1182,6 +1182,16 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1182,6 +1182,16 @@ class ObjectTemplateItem(BaseTemplateItem):
""" """
pass pass
def onReplaceObject(self, obj):
"""
Installation hook.
Called when installation process determined that object to install is
to replace an existing object on current site (it's not new).
`obj` parameter is the replaced object in its acquisition context.
Can be overridden by subclasses.
"""
pass
def setSafeReindexationMode(self, context): def setSafeReindexationMode(self, context):
""" """
Postpone indexations after unindexations. Postpone indexations after unindexations.
...@@ -1425,6 +1435,8 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1425,6 +1435,8 @@ class ObjectTemplateItem(BaseTemplateItem):
if not object_existed: if not object_existed:
# A new object was added, call the hook # A new object was added, call the hook
self.onNewObject(obj) self.onNewObject(obj)
else:
self.onReplaceObject(obj)
# mark a business template installation so in 'PortalType_afterClone' scripts # mark a business template installation so in 'PortalType_afterClone' scripts
# we can implement logical for reseting or not attributes (i.e reference). # we can implement logical for reseting or not attributes (i.e reference).
...@@ -4272,6 +4284,10 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem): ...@@ -4272,6 +4284,10 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem):
obj.workflow_history[wf_id] = WorkflowHistoryList([wf_history]) obj.workflow_history[wf_id] = WorkflowHistoryList([wf_history])
def onNewObject(self, _):
self._do_reset = True
onReplaceObject = onNewObject
def afterInstall(self): def afterInstall(self):
""" """
Reset component on the fly, because it is possible that those components Reset component on the fly, because it is possible that those components
...@@ -4284,7 +4300,8 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem): ...@@ -4284,7 +4300,8 @@ class _ZodbComponentTemplateItem(ObjectTemplateItem):
This reset is called at most 3 times in one business template This reset is called at most 3 times in one business template
installation. (for Document, Test, Extension) installation. (for Document, Test, Extension)
""" """
self.portal_components.reset(force=True) if getattr(self, '_do_reset', False):
self.portal_components.reset(force=True)
def afterUninstall(self): def afterUninstall(self):
self.portal_components.reset(force=True, self.portal_components.reset(force=True,
......
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