Commit 2b92f990 authored by Julien Muchembled's avatar Julien Muchembled

expand: optimize creation of new movements by not using propertyMap+_edit

parent db5e05dc
......@@ -45,7 +45,6 @@ class MovementCollectionDiff(object):
self._deletable_movement_list = []
self._new_movement_list = []
self._updatable_movement_list = []
self._property_dict_dict = {}
def getDeletableMovementList(self):
"""
......@@ -75,33 +74,17 @@ class MovementCollectionDiff(object):
def getUpdatableMovementList(self):
"""
Returns the list of movements which need
to be updated.
Returns movements which need to be updated, with properties to update
"""
return self._updatable_movement_list
def getMovementPropertyDict(self, movement):
"""
Returns a dict of all properties and values
to update an existing movement or to
create a new movement.
"""
# for updatable movement, property_dict is already calculated.
property_dict = self._property_dict_dict.get(movement)
# for new movement, property_dict should be calculated here.
if property_dict is None:
return _getPropertyAndCategoryList(movement)
else:
return property_dict
def addUpdatableMovement(self, movement, property_dict):
"""
Add an updatable movement to the diff definition
property_dict -- properties to update
"""
self._updatable_movement_list.append(movement)
self._property_dict_dict[movement] = property_dict
self._updatable_movement_list.append((movement, property_dict))
def _getPropertyAndCategoryList(document):
"""
......
......@@ -64,15 +64,7 @@ class IMovementCollectionDiff(Interface):
def getUpdatableMovementList():
"""
Returns the list of movements which need
to be updated.
"""
def getMovementPropertyDict(movement):
"""
Returns a dict of all properties and values
to update an existing movement or to
create a new movement.
Returns movements which need to be updated, with properties to update
"""
def addUpdatableMovement(movement, property_dict):
......
......@@ -164,13 +164,15 @@ class MovementCollectionUpdaterMixin:
# Apply Diff
for movement in movement_diff.getDeletableMovementList():
movement.getParentValue().deleteContent(movement.getId())
for movement in movement_diff.getUpdatableMovementList():
kw = movement_diff.getMovementPropertyDict(movement)
for movement, kw in movement_diff.getUpdatableMovementList():
movement.edit(**kw)
for property_id in kw.iterkeys():
for property_id in kw:
movement.clearRecordedProperty(property_id)
for movement in movement_diff.getNewMovementList():
kw = movement_diff.getMovementPropertyDict(movement)
movement = context.newContent(portal_type=self.movement_type, **kw)
d = movement.__dict__
# make sure our optimization does not touch existing persistent data
assert movement.isTempObject() and '_original' not in d
del movement.__dict__
movement = context.newContent(portal_type=self.movement_type)
d.update(movement.__dict__)
movement.__dict__ = d
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