Commit 11409e10 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Business Template: speed up build.

* remove needless copy of sub objects that are already recursively
  copied by their top most object.
* remove needless manage_beforeDelete() calls when copying objects.
parent cc549d7b
......@@ -163,6 +163,16 @@ def _recursiveRemoveUid(obj):
for subobj in obj.objectValues():
_recursiveRemoveUid(subobj)
def _delObjectWithoutHook(obj, id):
"""OFS.ObjectManager._delObject without calling manage_beforeDelete."""
ob = obj._getOb(id)
obj._objects = tuple([i for i in obj._objects if i['id'] != id])
obj._delOb(id)
try:
ob._v__object_deleted__ = 1
except:
pass
def removeAll(entry):
warn('removeAll is deprecated; use shutil.rmtree instead.',
DeprecationWarning)
......@@ -987,11 +997,9 @@ class ObjectTemplateItem(BaseTemplateItem):
def build_sub_objects(self, context, id_list, url, **kw):
# XXX duplicates code from build
p = context.getPortalObject()
for id in id_list:
relative_url = '/'.join([url,id])
obj = p.unrestrictedTraverse(relative_url)
obj = obj._getCopy(context)
obj = context._getOb(id)
obj = self.removeProperties(obj, 1,
self.isKeepWorkflowObject(relative_url),
self.isKeepWorkflowObjectLastHistoryOnly(relative_url))
......@@ -1000,9 +1008,9 @@ class ObjectTemplateItem(BaseTemplateItem):
# we must keep groups because they are deleted along with subobjects
groups = deepcopy(obj.groups)
if id_list:
self.build_sub_objects(context, id_list, relative_url)
self.build_sub_objects(obj, id_list, relative_url, copied=True)
for id_ in list(id_list):
obj._delObject(id_)
_delObjectWithoutHook(obj, id_)
if hasattr(aq_base(obj), 'groups'):
obj.groups = groups
self._objects[relative_url] = obj
......@@ -1029,9 +1037,9 @@ class ObjectTemplateItem(BaseTemplateItem):
# we must keep groups because they are deleted along with subobjects
groups = deepcopy(obj.groups)
if len(id_list) > 0:
self.build_sub_objects(context, id_list, relative_url)
self.build_sub_objects(obj, id_list, relative_url)
for id_ in list(id_list):
obj._delObject(id_)
_delObjectWithoutHook(obj, id_)
if hasattr(aq_base(obj), 'groups'):
obj.groups = groups
self._objects[relative_url] = obj
......@@ -1750,9 +1758,9 @@ class PathTemplateItem(ObjectTemplateItem):
groups = deepcopy(obj.groups)
if len(id_list) > 0:
if include_subobjects:
self.build_sub_objects(context, id_list, relative_url)
self.build_sub_objects(obj, id_list, relative_url)
for id_ in list(id_list):
obj._delObject(id_)
_delObjectWithoutHook(obj, id_)
if hasattr(aq_base(obj), 'groups'):
obj.groups = groups
self._objects[relative_url] = obj
......@@ -1897,19 +1905,17 @@ class CategoryTemplateItem(ObjectTemplateItem):
ObjectTemplateItem.__init__(self, id_list, tool_id=tool_id, **kw)
def build_sub_objects(self, context, id_list, url, **kw):
p = context.getPortalObject()
for id in id_list:
relative_url = '/'.join([url,id])
obj = p.unrestrictedTraverse(relative_url)
obj = obj._getCopy(context)
obj = context._getOb(id)
obj = self.removeProperties(obj, 1,
self.isKeepWorkflowObject(relative_url),
self.isKeepWorkflowObjectLastHistoryOnly(relative_url))
id_list = obj.objectIds()
if id_list:
self.build_sub_objects(context, id_list, relative_url)
self.build_sub_objects(obj, id_list, relative_url)
for id_ in list(id_list):
obj._delObject(id_)
_delObjectWithoutHook(obj, id_)
self._objects[relative_url] = obj
obj.wl_clearLocks()
......@@ -1932,12 +1938,9 @@ class CategoryTemplateItem(ObjectTemplateItem):
include_sub_categories = obj.__of__(context).getProperty('business_template_include_sub_categories', 0)
id_list = obj.objectIds()
if len(id_list) > 0 and include_sub_categories:
self.build_sub_objects(context, id_list, relative_url)
for id_ in list(id_list):
obj._delObject(id_)
else:
for id_ in list(id_list):
obj._delObject(id_)
self.build_sub_objects(obj, id_list, relative_url)
for id_ in list(id_list):
_delObjectWithoutHook(obj, id_)
self._objects[relative_url] = obj
obj.wl_clearLocks()
......
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