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()
if getattr(rule, 'updateMatrix', None) is not None:
rule.activate(
after_path_and_method_id=([rule.getPath(),],
['immediateReindexObject', 'recursiveImmediateReindexObject'])
).updateMatrix()
tag = script.id + '_' + rule.getPath()
# XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
rule.recursiveReindexObject(activate_kw={'tag': tag})
rule.activate(after_tag=tag).updateMatrix()
matrix = state_change['object']
if getattr(matrix, 'updateMatrix', None) is not None:
matrix.activate(
after_path_and_method_id=([matrix.getPath(),],
['immediateReindexObject', 'recursiveImmediateReindexObject'])
).updateMatrix()
tag = script.id + '_' + matrix.getPath()
# XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
matrix.recursiveReindexObject(activate_kw={'tag': tag})
matrix.activate(after_tag=tag).updateMatrix()
......@@ -206,14 +206,12 @@ for month in range(1, month_count + 1):
tr.deliver()
assert tr.getSimulationState() == 'delivered'
if not keep_grouping_reference:
tag = script.id + '_payment_indexation_' + payment.getPath()
payment.recursiveReindexObject(activate_kw={'tag': tag})
for line in payment.getMovementList(
portal_type=payment.getPortalAccountingMovementTypeList()):
if line.getGroupingReference():
line.activate(after_path_and_method_id=(
(payment.getPath(), line.getPath()),
('recursiveImmediateReindexObject',
'immediateReindexObject')),
).AccountingTransactionLine_resetGroupingReference()
line.activate(after_tag=tag).AccountingTransactionLine_resetGroupingReference()
else:
# other cases not supported for now
......
......@@ -118,14 +118,12 @@ for month in range(1, month_count + 1):
ptr.stop()
if not keep_grouping_reference:
tag = script.id + '_payment_indexation_' + ptr.getPath()
ptr.recursiveReindexObject(activate_kw={'tag': tag})
for line in ptr.getMovementList(
portal_type=ptr.getPortalAccountingMovementTypeList()):
if line.getGroupingReference():
line.activate(after_path_and_method_id=(
(ptr.getPath(), line.getPath()),
('recursiveImmediateReindexObject',
'immediateReindexObject')),
).AccountingTransactionLine_resetGroupingReference()
line.activate(after_tag=tag).AccountingTransactionLine_resetGroupingReference()
accounting_module.setProperty('current_content_script',
......
......@@ -93,9 +93,9 @@ if use_activity:
from_url=from_url)
if extra_header_dict:
method_kw['extra_header_dict'] = extra_header_dict
context.activate(
after_path_and_method_id=((context.getPath(),),
('immediateReindexObject', 'recursiveImmediateReindexObject'))).MailMessage_sendByActivity(
tag = script.id + '_reindex_' + context.getPath()
context.reindexObject(activate_kw={'tag': tag})
context.activate(after_tag=tag).MailMessage_sendByActivity(
method_kw=method_kw, **kw)
if download:
......
......@@ -39,7 +39,8 @@ credential_request = module.newContent(
credential_request.setCategoryList(category_list)
# Same tag is used as in ERP5 Login._setReference, in order to protect against
# 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
if not context.portal_membership.isAnonymousUser():
......@@ -58,15 +59,7 @@ if portal_preferences.getPreferredCredentialAlarmAutomaticCall():
message_str = "Credential Request Created."
else:
if portal_preferences.isPreferredEmailVerificationCheck():
# after_path_and_method_id argument is used below to not activate when
# 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(
credential_request.activate(activity='SQLQueue', after_tag=tag).CredentialRequest_sendSubmittedNotification(
context_url=context.absolute_url(),
notification_reference='credential_request-subscription')
message_str = "Thanks for your registration. You will be receive an email to activate your account."
......
......@@ -2,10 +2,13 @@ item_list = []
movement_list = context.getImmobilisationMovementList()
#context.log('movement_list %s' % context.getRelativeUrl(),[m.getPath() for m in movement_list])
movemement_path_list = []
tag = script.id + '_' + context.getPath()
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())
for item in movement.getAggregateValueList():
if item not in item_list:
item_list.append(item)
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']
# Set relative simulation movements profit_quantity to 0
movement_list = transaction.getMovementList()
all_simulation_movement_path_list = []
for movement in movement_list:
simulation_movement_list = movement.getDeliveryRelatedValueList(portal_type='Simulation Movement')
for simulation_movement in simulation_movement_list:
simulation_movement.edit(profit_quantity=0)
all_simulation_movement_path_list.extend([x.getPath() for x in simulation_movement_list])
relative_url = transaction.getRelativeUrl()
indexation_tag = script.id + '_' + relative_url
for movement in transaction.getMovementList():
for simulation_movement in movement.getDeliveryRelatedValueList(portal_type='Simulation Movement'):
simulation_movement.edit(profit_quantity=0, activate_kw={'tag': indexation_tag})
# Update from simulation, then adapt causality value
builder = transaction.portal_deliveries.amortisation_transaction_builder
builder.updateFromSimulation(transaction.getRelativeUrl())
tag = '%s_afterBuild' % transaction.getRelativeUrl()
transaction.activate(tag=tag,
after_path_and_method_id=(
all_simulation_movement_path_list,
('immediateReindexObject', 'recursiveImmediateReindexObject'))).AmortisationTransaction_afterBuild()
transaction.getPortalObject().portal_deliveries.amortisation_transaction_builder.updateFromSimulation(transaction.getRelativeUrl())
tag = relative_url + '_afterBuild'
transaction.activate(tag=tag, after_tag=indexation_tag).AmortisationTransaction_afterBuild()
# Automatic workflow
transaction.activate(after_tag=tag).updateCausalityState()
object = state_change['object']
delivery = object.getExplanationValue()
activate_kw = {}
document = state_change['object']
delivery = document.getExplanationValue()
if getattr(delivery, 'calculatePacking', None) is not None:
try:
container = object.getContainerValue()
activate_kw['after_path_and_method_id'] = (container.getPath(),
'recursiveImmediateReindexObject')
container = document.getContainerValue()
except AttributeError:
pass
delivery.activate(**activate_kw).calculatePacking()
container = None
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):
# An item can be expanded for amortisation only when related deliveries
# are no more in 'calculating' immobilisation_state
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(
after_path_and_method_id=(
related_packing_list_path_list, ('immediateReindexObject',
'recursiveImmediateReindexObject',
'updateImmobilisationState',)),
[x.getPath() for x in related_packing_list_list],
('updateImmobilisationState', ),
),
after_tag='expand_amortisation'
).immediateExpandAmortisation()
......
......@@ -74,6 +74,8 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
in delivery_dict.iteritems():
# First, duplicate the whole delivery document including its
# sub objects.
old_delivery_url = delivery.getRelativeUrl()
indexation_tag = 'MovementSplitSolver_solve_' + old_delivery_url
applied_rule = delivery.getCausalityRelatedValue(
portal_type='Applied Rule')
parent = delivery.getParentValue()
......@@ -81,11 +83,10 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
parent._duplicate(parent.manage_copyObjects(ids=ids))
)(parent, delivery.getId())
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()
reindex_path_list = [new_delivery.getPath()]
update_related_content_tag_list = []
update_related_content_tag_list = [indexation_tag]
old_simulation_movement_list = []
new_simulation_movement_list = []
......@@ -134,11 +135,9 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
new_movement_url)
update_related_content_tag_list.append('%s_updateRelatedContent'
% movement.getPath())
new_movement_path = movement.getPath().replace(
old_delivery_url, new_delivery_url)
reindex_path_list.append(new_movement_path)
reindex_path_list.extend(
[x.getPath() for x in simulation_movement_list])
for simulation_movement in simulation_movement_list:
# XXX: Tagged reindexation added to replace after_path_and_method_id. May be unnecessary.
simulation_movement.reindexObject(activate_kw={'tag': indexation_tag})
new_simulation_movement_list.extend(
[x.getRelativeUrl() for x in simulation_movement_list])
_delete(movement)
......@@ -152,7 +151,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
simulation_movement.setDelivery(
simulation_movement.getDelivery().replace(
'%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 = {}
for simulation_movement in simulation_movement_list:
delivery_movement = simulation_movement.getDeliveryValue()
......@@ -197,10 +196,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
new_root_simulation_movement_list]
cut_data = applied_rule.manage_cutObjects(id_list)
new_applied_rule.manage_pasteObjects(cut_data)
reindex_path_list = [\
x.replace('%s/' % applied_rule.getRelativeUrl(),
'%s/' % new_applied_rule.getRelativeUrl()) for x in \
reindex_path_list]
new_applied_rule.recursiveReindexObject(activate_kw={'tag': indexation_tag})
# Update variation category list
def _updateVariationCategoryList(document):
......@@ -225,9 +221,7 @@ class MovementSplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
mapping={'old_delivery_url':old_delivery_url}))
# Update causality state
activate_kw = dict(after_tag_list=update_related_content_tag_list,
after_path_and_method_id=(reindex_path_list,
('immediateReindexObject','recursiveImmediateReindexObject')))
activate_kw = {'after_tag_list': update_related_content_tag_list}
delivery.activate(**activate_kw).updateCausalityState()
new_delivery.activate(**activate_kw).updateCausalityState()
......
......@@ -49,9 +49,6 @@ class ProfitAndLoss(CopyToTarget):
target_quantity = delivery_line_quantity * simulation_movement.getDeliveryRatio()
added_quantity = simulation_movement.getQuantity() - target_quantity
simulation_movement.edit(profit_quantity=added_quantity)
delivery_line.activate(
after_path_and_method_id=(
simulation_movement.getPath(),
['immediateReindexObject', 'recursiveImmediateReindexObject']
)
).edit()
tag = 'ProfitAndLoss_solve_' + simulation_movement.getPath()
simulation_movement.reindexObject(activate_kw={'tag': tag})
delivery_line.activate(after_tag=tag).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