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,37 +1291,28 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -1291,37 +1291,28 @@ 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
recursive_path_list.append(from_path) path_match = path + '/'
# Check that container support iteration of sub_content_id for object_key in object_key_list:
if getattr(aq_base(container), 'objectIds', None) is not None: if path_match.startswith(object_key + '/'):
fillRecursivePathList(['%s/%s' % (from_path, sub_content_id) for\ to_delete_dict[path] = action
sub_content_id in container.objectIds()]) for path, action in to_delete_dict.iteritems():
fillRecursivePathList(object_key_list) document = self.unrestrictedResolveValue(portal, path, None)
for recursive_path in recursive_path_list:
if recursive_path in update_dict:
action = update_dict[recursive_path]
if action in ('remove', 'save_and_remove'):
document = self.unrestrictedResolveValue(portal, recursive_path, None)
if document is None: if document is None:
# It happens if the parent of target path is removed before
continue continue
if getattr(aq_base(document), 'getParentValue', None) is not None: if getattr(aq_base(document), 'getParentValue', None) is None:
# regular ERP5 object
parent = document.getParentValue()
else:
parent = document.aq_parent parent = document.aq_parent
else:
parent = document.getParentValue()
document_id = document.getId() document_id = document.getId()
container_path_list = recursive_path.split('/')[:-1] self._backupObject(action, trashbin, path.split('/')[:-1],
self._backupObject(action, trashbin, container_path_list,
document_id) document_id)
parent.manage_delObjects([document_id]) parent.manage_delObjects([document_id])
......
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