Commit 207bdea9 authored by Nicolas Wavrant's avatar Nicolas Wavrant

CMFActivity: Memoize dependant activities when they share the same serialization tag

Otherwise, for each activity, a read is called on activity tables for
each activity sharing the serialization tag
parent 6821549e
...@@ -136,14 +136,22 @@ class Queue(object): ...@@ -136,14 +136,22 @@ class Queue(object):
return EXCEPTION return EXCEPTION
return VALID return VALID
def getDependentMessageList(self, activity_tool, message): def getDependentMessageList(self, activity_tool, message, serialization_cache_dict):
message_list = [] message_list = []
for k, v in message.activity_kw.iteritems(): for k, v in message.activity_kw.iteritems():
message_list += activity_tool.getDependentMessageList(message, k, v) # If dependant message list already found for serialization, then use cache
if k == 'serialization_tag':
if serialization_cache_dict.get(v):
message_list += serialization_cache_dict.get(v)
else:
serialization_cache_dict[v] = activity_tool.getDependentMessageList(message, k, v)
message_list += serialization_cache_dict[v]
else:
message_list += activity_tool.getDependentMessageList(message, k, v)
return message_list return message_list
def getExecutableMessageList(self, activity_tool, message, message_dict, def getExecutableMessageList(self, activity_tool, message, message_dict,
validation_text_dict, now_date=None): validation_text_dict, serialization_cache_dict, now_date=None):
"""Get messages which have no dependent message, and store them in the dictionary. """Get messages which have no dependent message, and store them in the dictionary.
If the passed message itself is executable, simply store only that message. If the passed message itself is executable, simply store only that message.
...@@ -165,7 +173,7 @@ class Queue(object): ...@@ -165,7 +173,7 @@ class Queue(object):
cached_result = validation_text_dict.get(message.order_validation_text) cached_result = validation_text_dict.get(message.order_validation_text)
if cached_result is None: if cached_result is None:
message_list = self.getDependentMessageList(activity_tool, message) message_list = self.getDependentMessageList(activity_tool, message, serialization_cache_dict)
transaction.commit() # Release locks. transaction.commit() # Release locks.
if message_list: if message_list:
# The result is not empty, so this message is not executable. # The result is not empty, so this message is not executable.
...@@ -180,7 +188,8 @@ class Queue(object): ...@@ -180,7 +188,8 @@ class Queue(object):
message_dict[message.uid] = None message_dict[message.uid] = None
try: try:
self.getExecutableMessageList(activity_tool, m, message_dict, self.getExecutableMessageList(activity_tool, m, message_dict,
validation_text_dict, now_date=now_date) validation_text_dict, serialization_cache_dict,
now_date=now_date)
finally: finally:
del message_dict[message.uid] del message_dict[message.uid]
else: else:
......
...@@ -366,11 +366,17 @@ class SQLBase(Queue): ...@@ -366,11 +366,17 @@ class SQLBase(Queue):
validation_text_dict = {'none': 1} validation_text_dict = {'none': 1}
message_dict = {} message_dict = {}
serialization_cache_dict = {}
for line in result: for line in result:
message = Message.load(line.message, uid=line.uid, line=line) message = Message.load(line.message, uid=line.uid, line=line)
if not hasattr(message, 'order_validation_text'): # BBB if not hasattr(message, 'order_validation_text'): # BBB
message.order_validation_text = self.getOrderValidationText(message) message.order_validation_text = self.getOrderValidationText(message)
if 'serialization_tag' in message.activity_kw:
serialization_cache_dict.setdefault(
message.activity_kw['serialization_tag'], []
)
self.getExecutableMessageList(activity_tool, message, message_dict, self.getExecutableMessageList(activity_tool, message, message_dict,
serialization_cache_dict,
validation_text_dict, now_date=now_date) validation_text_dict, now_date=now_date)
if message_dict: if message_dict:
distributable_uid_set = set() distributable_uid_set = set()
......
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