Commit 18b0862e authored by Vincent Pelletier's avatar Vincent Pelletier

BusinessTemplate: Kill fillRecursivePathList.

fillRecursivePathList could load massive amounts of objects (ex:
all signatures below portal_synchronizations) even if no object was to
be removed. Instead, just iterate given lists (objects handled by
current instance, and actions to perform) and do as much rocessng before
actually attempt to load any object.

Sadly, the data structures available to this code induce an ugly O(n*m)
code, which may be optimised to O(m + log(n)) with more complex code if
really needed (but then, data structure should be improved, with a much
broader effect).
parent 28eafad4
...@@ -1291,39 +1291,30 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1291,39 +1291,30 @@ class ObjectTemplateItem(BaseTemplateItem):
obj.groups = new_groups_dict obj.groups = new_groups_dict
# restore previous activities execution order # restore previous activities execution order
context.setPlacelessDefaultReindexParameters(**original_reindex_parameters) context.setPlacelessDefaultReindexParameters(**original_reindex_parameters)
# Do not forget to delete all remaining objects if asked by user to_delete_dict = {}
# Fetch all sub objects path recursively # XXX: it is not clear why update_dict would contain subojects of any
recursive_path_list = [] # element of object_key_list, and not just these objects themselves.
def fillRecursivePathList(from_path_list): # XXX: why does update_dict contain the path of documents not managed
for from_path in from_path_list: # by current instance ?
container = portal.unrestrictedTraverse(from_path, None) for path, action in update_dict.iteritems():
if container is not None: if action not in ('remove', 'save_and_remove'):
if from_path in recursive_path_list: continue
continue path_match = path + '/'
recursive_path_list.append(from_path) for object_key in object_key_list:
# Check that container support iteration of sub_content_id if path_match.startswith(object_key + '/'):
if getattr(aq_base(container), 'objectIds', None) is not None: to_delete_dict[path] = action
fillRecursivePathList(['%s/%s' % (from_path, sub_content_id) for\ for path, action in to_delete_dict.iteritems():
sub_content_id in container.objectIds()]) document = self.unrestrictedResolveValue(portal, path, None)
fillRecursivePathList(object_key_list) if document is None:
for recursive_path in recursive_path_list: continue
if recursive_path in update_dict: if getattr(aq_base(document), 'getParentValue', None) is None:
action = update_dict[recursive_path] parent = document.aq_parent
if action in ('remove', 'save_and_remove'): else:
document = self.unrestrictedResolveValue(portal, recursive_path, None) parent = document.getParentValue()
if document is None: document_id = document.getId()
# It happens if the parent of target path is removed before self._backupObject(action, trashbin, path.split('/')[:-1],
continue document_id)
if getattr(aq_base(document), 'getParentValue', None) is not None: parent.manage_delObjects([document_id])
# regular ERP5 object
parent = document.getParentValue()
else:
parent = document.aq_parent
document_id = document.getId()
container_path_list = recursive_path.split('/')[:-1]
self._backupObject(action, trashbin, container_path_list,
document_id)
parent.manage_delObjects([document_id])
self.afterInstall() self.afterInstall()
......
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