Commit 37f90de1 authored by Vincent Pelletier's avatar Vincent Pelletier

CMFActivity.ActivityBuffer: Drop duplicate activity reference.

Activity is expected to be appended to message_list_dict's value already,
no need to append it to queued_activity.
In turn, this allows getting rid of _prepare_args.
parent fef43364
...@@ -31,13 +31,13 @@ from collections import defaultdict ...@@ -31,13 +31,13 @@ from collections import defaultdict
import transaction import transaction
class ActivityBuffer(TM): class ActivityBuffer(TM):
activity_tool = None
def __init__(self): def __init__(self):
self.queued_activity = []
self.message_list_dict = defaultdict(list) self.message_list_dict = defaultdict(list)
self.uid_set_dict = defaultdict(set) self.uid_set_dict = defaultdict(set)
def _clear(self): def _clear(self):
del self.queued_activity[:]
self.message_list_dict.clear() self.message_list_dict.clear()
self.uid_set_dict.clear() self.uid_set_dict.clear()
self.activity_tool = None self.activity_tool = None
...@@ -49,26 +49,21 @@ class ActivityBuffer(TM): ...@@ -49,26 +49,21 @@ class ActivityBuffer(TM):
return self.uid_set_dict[activity] return self.uid_set_dict[activity]
def _register(self, activity_tool): def _register(self, activity_tool):
if not self._registered: TM._register(self)
if self.activity_tool is None:
self.activity_tool = activity_tool self.activity_tool = activity_tool
TM._register(self) transaction.get().addBeforeCommitHook(self._prepare)
self._prepare_args = 0,
if self._prepare_args:
transaction.get().addBeforeCommitHook(self._prepare, self._prepare_args)
self._prepare_args = None
_abort = _finish = _clear _abort = _finish = _clear
def _prepare(self, queued): def _prepare(self):
try: try:
activity_tool = self.activity_tool activity_tool = self.activity_tool
# Try to push all messages # Try to push all messages
activity_dict = defaultdict(list) for activity, message_list in self.message_list_dict.iteritems():
for activity, message in self.queued_activity[queued:]:
activity_dict[activity].append(message)
for activity, message_list in activity_dict.iteritems():
activity.prepareQueueMessageList(activity_tool, message_list) activity.prepareQueueMessageList(activity_tool, message_list)
self._prepare_args = len(self.queued_activity), self.message_list_dict.clear()
self.activity_tool = None
except: except:
LOG('ActivityBuffer', ERROR, "exception during _prepare", LOG('ActivityBuffer', ERROR, "exception during _prepare",
error=sys.exc_info()) error=sys.exc_info())
...@@ -78,8 +73,6 @@ class ActivityBuffer(TM): ...@@ -78,8 +73,6 @@ class ActivityBuffer(TM):
self._register(activity_tool) self._register(activity_tool)
assert not message.is_registered, message assert not message.is_registered, message
activity.registerMessage(self, activity_tool, message) activity.registerMessage(self, activity_tool, message)
if message.is_registered:
self.queued_activity.append((activity, message))
def sortKey(self, *ignored): def sortKey(self, *ignored):
"""Activities must be finished before databases commit transactions.""" """Activities must be finished before databases commit transactions."""
......
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