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
import transaction
class ActivityBuffer(TM):
activity_tool = None
def __init__(self):
self.queued_activity = []
self.message_list_dict = defaultdict(list)
self.uid_set_dict = defaultdict(set)
def _clear(self):
del self.queued_activity[:]
self.message_list_dict.clear()
self.uid_set_dict.clear()
self.activity_tool = None
......@@ -49,26 +49,21 @@ class ActivityBuffer(TM):
return self.uid_set_dict[activity]
def _register(self, activity_tool):
if not self._registered:
TM._register(self)
if self.activity_tool is None:
self.activity_tool = activity_tool
TM._register(self)
self._prepare_args = 0,
if self._prepare_args:
transaction.get().addBeforeCommitHook(self._prepare, self._prepare_args)
self._prepare_args = None
transaction.get().addBeforeCommitHook(self._prepare)
_abort = _finish = _clear
def _prepare(self, queued):
def _prepare(self):
try:
activity_tool = self.activity_tool
# Try to push all messages
activity_dict = defaultdict(list)
for activity, message in self.queued_activity[queued:]:
activity_dict[activity].append(message)
for activity, message_list in activity_dict.iteritems():
for activity, message_list in self.message_list_dict.iteritems():
activity.prepareQueueMessageList(activity_tool, message_list)
self._prepare_args = len(self.queued_activity),
self.message_list_dict.clear()
self.activity_tool = None
except:
LOG('ActivityBuffer', ERROR, "exception during _prepare",
error=sys.exc_info())
......@@ -78,8 +73,6 @@ class ActivityBuffer(TM):
self._register(activity_tool)
assert not message.is_registered, message
activity.registerMessage(self, activity_tool, message)
if message.is_registered:
self.queued_activity.append((activity, message))
def sortKey(self, *ignored):
"""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