Commit 42414c4d authored by Rafael Monnerat's avatar Rafael Monnerat

erp5_open_trade: Optimise calls of updateSimulation to not overcall the API

  This optimisation aims reduce the potential activity leak when over launching accross multiple activities/transactions the updateSimulation.
  SubscriptionItem: Add a method to call updateSimulation from sqldict activities
    updateExpandableRootSimulation allow launch activities in a safer matter and have lower calls.
parent bca962b1
...@@ -176,6 +176,10 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin, ...@@ -176,6 +176,10 @@ class SubscriptionItem(Item, CompositionMixin, MovementGeneratorMixin,
return result return result
def updateExpandableRootSimulation(self):
""" Utility method to help use updateSimulation with SQLDict on activities """
self.updateSimulation(expand_root=1)
# XXX BELOW HACKS # XXX BELOW HACKS
def getResource(self): def getResource(self):
open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line') open_order_line = self.getAggregateRelatedValue(portal_type='Open Sale Order Line')
......
kw = {}
if params is None:
params = {}
last_active_process = context.getLastActiveProcess()
if not params.get('full', False) and last_active_process is not None:
# fetch only objects modified since last alarm run
kw['indexation_timestamp'] = '>= %s' % last_active_process.getStartDate().ISO()
# register active process in order to have "windows" of last indexed objects
context.newActiveProcess().getRelativeUrl()
portal = context.getPortalObject()
kw['portal_type'] = portal.getPortalOpenOrderTypeList()
kw['children_portal_type'] = [ i + " Line" for i in portal.getPortalOpenOrderTypeList()]
portal.portal_catalog.searchAndActivate(
method_id='OpenOrder_updateSimulation',
packet_size=1,
activate_kw={'tag':tag},
**kw
)
# make alarm run once at time
context.activate(after_tag=tag).getId()
...@@ -48,40 +48,6 @@ ...@@ -48,40 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
kw = {}\n
if params is None:\n
params = {}\n
\n
last_active_process = context.getLastActiveProcess()\n
if not params.get(\'full\', False) and last_active_process is not None:\n
# fetch only objects modified since last alarm run\n
kw[\'indexation_timestamp\'] = \'>= %s\' % last_active_process.getStartDate().ISO()\n
\n
# register active process in order to have "windows" of last indexed objects\n
context.newActiveProcess().getRelativeUrl()\n
\n
portal = context.getPortalObject()\n
\n
kw[\'portal_type\'] = portal.getPortalOpenOrderTypeList()\n
\n
portal.portal_catalog.searchAndActivate(\n
method_id=\'OpenOrder_updateSimulation\',\n
# method_kw={\'tag\': tag}, # XXX: Post merge compatibility, maybe OpenOrder_updateSimulation shall be reconfigured to being able to expand without activity (immediate expand)\n
packet_size=1, # As OpenOrder_updateSimulation can generate big transaction separate the calls\n
activate_kw={\'tag\':tag},\n
**kw # XXX: In one query put parents of last modified lines\n
)\n
\n
# make alarm run once at time\n
context.activate(after_tag=tag).getId()\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value> <value> <string>tag, fixit, params</string> </value>
......
subscription_item_set = set() subscription_item_set = set()
portal = context.getPortalObject()
def hasUpdateSimulationActivity(item):
for activity in portal.portal_activities.getMessageList(
method_id="_updateSimulation", path="/erp5/" + item.getRelativeUrl()):
if activity.kw == {"expand_root" : 1}:
return True
return False
for open_order_line in context.objectValues(): for open_order_line in context.objectValues():
for ob in [open_order_line] + open_order_line.getCellValueList(): for ob in [open_order_line] + open_order_line.getCellValueList():
...@@ -6,4 +15,12 @@ for open_order_line in context.objectValues(): ...@@ -6,4 +15,12 @@ for open_order_line in context.objectValues():
if getattr(item.aq_explicit, 'updateSimulation', None) is not None and \ if getattr(item.aq_explicit, 'updateSimulation', None) is not None and \
item not in subscription_item_set: item not in subscription_item_set:
subscription_item_set.add(item) subscription_item_set.add(item)
item.updateSimulation(expand_root=1) # Optmise for not launch an activity when some activity
# is there already pending for the same purpose.
if not hasUpdateSimulationActivity(item):
if getattr(item.aq_explicit, 'updateExpandableRootSimulation', None):
# If this method is implemented use activate to only execute it
# once.
item.activate().updateExpandableRootSimulation()
else:
item.updateSimulation(expand_root=1)
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