Commit 028c9ad7 authored by Vincent Pelletier's avatar Vincent Pelletier

all: Replace after_path_and_method_id on reindexation methods by after_tag

after_method_id is too aggressive a dependency.
after_path_and_method_id is marginally better, but is bad practice
nevertheless, as such activity dependencies remain very hard to introspect.
Tags allow more variations, and are hence easier to follow.
Also, add XXX comments when (recursive) reindexation is only added to
represent the dependency, without certainty that a reindexation is actually
needed per-se: maybe another place in the code chould just appropriately
tag its reindexation activities instead, saving at least the cost of
spawning one more activity set, and at most the cost of actually
reindexing these documents.
parent 9d9e4bbc
rule = state_change['object'].getParentValue() rule = state_change['object'].getParentValue()
if getattr(rule, 'updateMatrix', None) is not None: if getattr(rule, 'updateMatrix', None) is not None:
rule.activate( tag = script.id + '_' + rule.getPath()
after_path_and_method_id=([rule.getPath(),], # XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
['immediateReindexObject', 'recursiveImmediateReindexObject']) rule.recursiveReindexObject(activate_kw={'tag': tag})
).updateMatrix() rule.activate(after_tag=tag).updateMatrix()
matrix = state_change['object'] matrix = state_change['object']
if getattr(matrix, 'updateMatrix', None) is not None: if getattr(matrix, 'updateMatrix', None) is not None:
matrix.activate( tag = script.id + '_' + matrix.getPath()
after_path_and_method_id=([matrix.getPath(),], # XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
['immediateReindexObject', 'recursiveImmediateReindexObject']) matrix.recursiveReindexObject(activate_kw={'tag': tag})
).updateMatrix() matrix.activate(after_tag=tag).updateMatrix()
...@@ -206,14 +206,12 @@ for month in range(1, month_count + 1): ...@@ -206,14 +206,12 @@ for month in range(1, month_count + 1):
tr.deliver() tr.deliver()
assert tr.getSimulationState() == 'delivered' assert tr.getSimulationState() == 'delivered'
if not keep_grouping_reference: if not keep_grouping_reference:
tag = script.id + '_payment_indexation_' + payment.getPath()
payment.recursiveReindexObject(activate_kw={'tag': tag})
for line in payment.getMovementList( for line in payment.getMovementList(
portal_type=payment.getPortalAccountingMovementTypeList()): portal_type=payment.getPortalAccountingMovementTypeList()):
if line.getGroupingReference(): if line.getGroupingReference():
line.activate(after_path_and_method_id=( line.activate(after_tag=tag).AccountingTransactionLine_resetGroupingReference()
(payment.getPath(), line.getPath()),
('recursiveImmediateReindexObject',
'immediateReindexObject')),
).AccountingTransactionLine_resetGroupingReference()
else: else:
# other cases not supported for now # other cases not supported for now
......
...@@ -118,14 +118,12 @@ for month in range(1, month_count + 1): ...@@ -118,14 +118,12 @@ for month in range(1, month_count + 1):
ptr.stop() ptr.stop()
if not keep_grouping_reference: if not keep_grouping_reference:
tag = script.id + '_payment_indexation_' + ptr.getPath()
ptr.recursiveReindexObject(activate_kw={'tag': tag})
for line in ptr.getMovementList( for line in ptr.getMovementList(
portal_type=ptr.getPortalAccountingMovementTypeList()): portal_type=ptr.getPortalAccountingMovementTypeList()):
if line.getGroupingReference(): if line.getGroupingReference():
line.activate(after_path_and_method_id=( line.activate(after_tag=tag).AccountingTransactionLine_resetGroupingReference()
(ptr.getPath(), line.getPath()),
('recursiveImmediateReindexObject',
'immediateReindexObject')),
).AccountingTransactionLine_resetGroupingReference()
accounting_module.setProperty('current_content_script', accounting_module.setProperty('current_content_script',
......
...@@ -93,9 +93,9 @@ if use_activity: ...@@ -93,9 +93,9 @@ if use_activity:
from_url=from_url) from_url=from_url)
if extra_header_dict: if extra_header_dict:
method_kw['extra_header_dict'] = extra_header_dict method_kw['extra_header_dict'] = extra_header_dict
context.activate( tag = script.id + '_reindex_' + context.getPath()
after_path_and_method_id=((context.getPath(),), context.reindexObject(activate_kw={'tag': tag})
('immediateReindexObject', 'recursiveImmediateReindexObject'))).MailMessage_sendByActivity( context.activate(after_tag=tag).MailMessage_sendByActivity(
method_kw=method_kw, **kw) method_kw=method_kw, **kw)
if download: if download:
......
...@@ -39,7 +39,8 @@ credential_request = module.newContent( ...@@ -39,7 +39,8 @@ credential_request = module.newContent(
credential_request.setCategoryList(category_list) credential_request.setCategoryList(category_list)
# Same tag is used as in ERP5 Login._setReference, in order to protect against # Same tag is used as in ERP5 Login._setReference, in order to protect against
# concurrency between Credential Request and Person object too # concurrency between Credential Request and Person object too
credential_request.reindexObject(activate_kw=dict(tag='set_login_%s' % reference.encode('hex'))) tag = 'set_login_%s' % reference.encode('hex')
credential_request.reindexObject(activate_kw={'tag': tag})
#We attach the current user to the credential request if not anonymous #We attach the current user to the credential request if not anonymous
if not context.portal_membership.isAnonymousUser(): if not context.portal_membership.isAnonymousUser():
...@@ -58,15 +59,7 @@ if portal_preferences.getPreferredCredentialAlarmAutomaticCall(): ...@@ -58,15 +59,7 @@ if portal_preferences.getPreferredCredentialAlarmAutomaticCall():
message_str = "Credential Request Created." message_str = "Credential Request Created."
else: else:
if portal_preferences.isPreferredEmailVerificationCheck(): if portal_preferences.isPreferredEmailVerificationCheck():
# after_path_and_method_id argument is used below to not activate when credential_request.activate(activity='SQLQueue', after_tag=tag).CredentialRequest_sendSubmittedNotification(
# Crededial request object is not indexed yet. This is needed because when
# the method searchAndActivate from catalog is called, if the object is not
# indexed, the e-mail is not sent.
method_id_list = ('immediateReindexObject', 'recursiveImmediateReindexObject')
path_and_method_id = (credential_request.getPath(), method_id_list)
activity_kw = dict(activity='SQLQueue',
after_path_and_method_id=path_and_method_id)
credential_request.activate(**activity_kw).CredentialRequest_sendSubmittedNotification(
context_url=context.absolute_url(), context_url=context.absolute_url(),
notification_reference='credential_request-subscription') notification_reference='credential_request-subscription')
message_str = "Thanks for your registration. You will be receive an email to activate your account." message_str = "Thanks for your registration. You will be receive an email to activate your account."
......
...@@ -2,10 +2,13 @@ item_list = [] ...@@ -2,10 +2,13 @@ item_list = []
movement_list = context.getImmobilisationMovementList() movement_list = context.getImmobilisationMovementList()
#context.log('movement_list %s' % context.getRelativeUrl(),[m.getPath() for m in movement_list]) #context.log('movement_list %s' % context.getRelativeUrl(),[m.getPath() for m in movement_list])
movemement_path_list = [] movemement_path_list = []
tag = script.id + '_' + context.getPath()
for movement in movement_list: for movement in movement_list:
# XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
movement.recursiveReindexObject(activate_kw={'tag': tag})
movemement_path_list.append(movement.getPath()) movemement_path_list.append(movement.getPath())
for item in movement.getAggregateValueList(): for item in movement.getAggregateValueList():
if item not in item_list: if item not in item_list:
item_list.append(item) item_list.append(item)
for item in item_list: for item in item_list:
item.activate(tag='expand_amortisation', after_path_and_method_id=(movemement_path_list, ('immediateReindexObject', 'recursiveImmediateReindexObject', 'updateImmobilisationState',) )).expandAmortisation() item.activate(tag='expand_amortisation', after_tag=tag, after_path_and_method_id=(movemement_path_list, ('updateImmobilisationState',) )).expandAmortisation()
transaction = state_change['object'] transaction = state_change['object']
# Set relative simulation movements profit_quantity to 0 # Set relative simulation movements profit_quantity to 0
movement_list = transaction.getMovementList() relative_url = transaction.getRelativeUrl()
all_simulation_movement_path_list = [] indexation_tag = script.id + '_' + relative_url
for movement in movement_list: for movement in transaction.getMovementList():
simulation_movement_list = movement.getDeliveryRelatedValueList(portal_type='Simulation Movement') for simulation_movement in movement.getDeliveryRelatedValueList(portal_type='Simulation Movement'):
for simulation_movement in simulation_movement_list: simulation_movement.edit(profit_quantity=0, activate_kw={'tag': indexation_tag})
simulation_movement.edit(profit_quantity=0)
all_simulation_movement_path_list.extend([x.getPath() for x in simulation_movement_list])
# Update from simulation, then adapt causality value # Update from simulation, then adapt causality value
builder = transaction.portal_deliveries.amortisation_transaction_builder transaction.getPortalObject().portal_deliveries.amortisation_transaction_builder.updateFromSimulation(transaction.getRelativeUrl())
builder.updateFromSimulation(transaction.getRelativeUrl()) tag = relative_url + '_afterBuild'
tag = '%s_afterBuild' % transaction.getRelativeUrl() transaction.activate(tag=tag, after_tag=indexation_tag).AmortisationTransaction_afterBuild()
transaction.activate(tag=tag,
after_path_and_method_id=(
all_simulation_movement_path_list,
('immediateReindexObject', 'recursiveImmediateReindexObject'))).AmortisationTransaction_afterBuild()
# Automatic workflow # Automatic workflow
transaction.activate(after_tag=tag).updateCausalityState() transaction.activate(after_tag=tag).updateCausalityState()
object = state_change['object'] document = state_change['object']
delivery = object.getExplanationValue() delivery = document.getExplanationValue()
activate_kw = {}
if getattr(delivery, 'calculatePacking', None) is not None: if getattr(delivery, 'calculatePacking', None) is not None:
try: try:
container = object.getContainerValue() container = document.getContainerValue()
activate_kw['after_path_and_method_id'] = (container.getPath(),
'recursiveImmediateReindexObject')
except AttributeError: except AttributeError:
pass container = None
delivery.activate(**activate_kw).calculatePacking() if container is None:
tag = None
else:
tag = script.id + '_' + container.getPath()
# XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
container.recursiveReindexObject(activate_kw={'tag': tag})
delivery.activate(after_tag=tag).calculatePacking()
...@@ -1075,12 +1075,18 @@ class ImmobilisableItem(Item, Amount): ...@@ -1075,12 +1075,18 @@ class ImmobilisableItem(Item, Amount):
# An item can be expanded for amortisation only when related deliveries # An item can be expanded for amortisation only when related deliveries
# are no more in 'calculating' immobilisation_state # are no more in 'calculating' immobilisation_state
related_packing_list_list = self.getAggregateRelatedValueList() related_packing_list_list = self.getAggregateRelatedValueList()
related_packing_list_path_list = [x.getPath() for x in related_packing_list_list] for related_packing_list in related_packing_list_list:
# XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
related_packing_list.recursiveReindexObject(
# Recycle a tag we must wait on anyway.
# XXX: it would be better to have per-item tags...
activate_kw={'tag': 'expand_amortisation'},
)
self.activate( self.activate(
after_path_and_method_id=( after_path_and_method_id=(
related_packing_list_path_list, ('immediateReindexObject', [x.getPath() for x in related_packing_list_list],
'recursiveImmediateReindexObject', ('updateImmobilisationState', ),
'updateImmobilisationState',)), ),
after_tag='expand_amortisation' after_tag='expand_amortisation'
).immediateExpandAmortisation() ).immediateExpandAmortisation()
......
...@@ -74,6 +74,8 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -74,6 +74,8 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
in delivery_dict.iteritems(): in delivery_dict.iteritems():
# First, duplicate the whole delivery document including its # First, duplicate the whole delivery document including its
# sub objects. # sub objects.
old_delivery_url = delivery.getRelativeUrl()
indexation_tag = 'MovementSplitSolver_solve_' + old_delivery_url
applied_rule = delivery.getCausalityRelatedValue( applied_rule = delivery.getCausalityRelatedValue(
portal_type='Applied Rule') portal_type='Applied Rule')
parent = delivery.getParentValue() parent = delivery.getParentValue()
...@@ -81,11 +83,10 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -81,11 +83,10 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
parent._duplicate(parent.manage_copyObjects(ids=ids)) parent._duplicate(parent.manage_copyObjects(ids=ids))
)(parent, delivery.getId()) )(parent, delivery.getId())
new_delivery = parent[cp['new_id']] new_delivery = parent[cp['new_id']]
old_delivery_url = delivery.getRelativeUrl() new_delivery.recursiveReindexObject(activate_kw={'tag': indexation_tag})
new_delivery_url = new_delivery.getRelativeUrl() new_delivery_url = new_delivery.getRelativeUrl()
reindex_path_list = [new_delivery.getPath()] update_related_content_tag_list = [indexation_tag]
update_related_content_tag_list = []
old_simulation_movement_list = [] old_simulation_movement_list = []
new_simulation_movement_list = [] new_simulation_movement_list = []
...@@ -134,11 +135,9 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -134,11 +135,9 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
new_movement_url) new_movement_url)
update_related_content_tag_list.append('%s_updateRelatedContent' update_related_content_tag_list.append('%s_updateRelatedContent'
% movement.getPath()) % movement.getPath())
new_movement_path = movement.getPath().replace( for simulation_movement in simulation_movement_list:
old_delivery_url, new_delivery_url) # XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
reindex_path_list.append(new_movement_path) simulation_movement.reindexObject(activate_kw={'tag': indexation_tag})
reindex_path_list.extend(
[x.getPath() for x in simulation_movement_list])
new_simulation_movement_list.extend( new_simulation_movement_list.extend(
[x.getRelativeUrl() for x in simulation_movement_list]) [x.getRelativeUrl() for x in simulation_movement_list])
_delete(movement) _delete(movement)
...@@ -152,7 +151,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -152,7 +151,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
simulation_movement.setDelivery( simulation_movement.setDelivery(
simulation_movement.getDelivery().replace( simulation_movement.getDelivery().replace(
'%s/' % old_delivery_url, '%s/' % new_delivery_url)) '%s/' % old_delivery_url, '%s/' % new_delivery_url))
reindex_path_list.append(simulation_movement.getRelativeUrl()) simulation_moment.reindexObjec(activate_kw={'tag': indexation_tag})
quantity_dict = {} quantity_dict = {}
for simulation_movement in simulation_movement_list: for simulation_movement in simulation_movement_list:
delivery_movement = simulation_movement.getDeliveryValue() delivery_movement = simulation_movement.getDeliveryValue()
...@@ -197,10 +196,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -197,10 +196,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
new_root_simulation_movement_list] new_root_simulation_movement_list]
cut_data = applied_rule.manage_cutObjects(id_list) cut_data = applied_rule.manage_cutObjects(id_list)
new_applied_rule.manage_pasteObjects(cut_data) new_applied_rule.manage_pasteObjects(cut_data)
reindex_path_list = [\ new_applied_rule.recursiveReindexObject(activate_kw={'tag': indexation_tag})
x.replace('%s/' % applied_rule.getRelativeUrl(),
'%s/' % new_applied_rule.getRelativeUrl()) for x in \
reindex_path_list]
# Update variation category list # Update variation category list
def _updateVariationCategoryList(document): def _updateVariationCategoryList(document):
...@@ -225,9 +221,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -225,9 +221,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
mapping={'old_delivery_url':old_delivery_url})) mapping={'old_delivery_url':old_delivery_url}))
# Update causality state # Update causality state
activate_kw = dict(after_tag_list=update_related_content_tag_list, activate_kw = {'after_tag_list': update_related_content_tag_list}
after_path_and_method_id=(reindex_path_list,
('immediateReindexObject','recursiveImmediateReindexObject')))
delivery.activate(**activate_kw).updateCausalityState() delivery.activate(**activate_kw).updateCausalityState()
new_delivery.activate(**activate_kw).updateCausalityState() new_delivery.activate(**activate_kw).updateCausalityState()
......
...@@ -49,9 +49,6 @@ class ProfitAndLoss(CopyToTarget): ...@@ -49,9 +49,6 @@ class ProfitAndLoss(CopyToTarget):
target_quantity = delivery_line_quantity * simulation_movement.getDeliveryRatio() target_quantity = delivery_line_quantity * simulation_movement.getDeliveryRatio()
added_quantity = simulation_movement.getQuantity() - target_quantity added_quantity = simulation_movement.getQuantity() - target_quantity
simulation_movement.edit(profit_quantity=added_quantity) simulation_movement.edit(profit_quantity=added_quantity)
delivery_line.activate( tag = 'ProfitAndLoss_solve_' + simulation_movement.getPath()
after_path_and_method_id=( simulation_movement.reindexObject(activate_kw={'tag': tag})
simulation_movement.getPath(), delivery_line.activate(after_tag=tag).edit()
['immediateReindexObject', 'recursiveImmediateReindexObject']
)
).edit()
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