Commit a807d07f authored by Yoshinori Okuji's avatar Yoshinori Okuji

Use prepareQueueMessageList if available.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2829 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c0885116
...@@ -28,9 +28,9 @@ from zLOG import LOG, ERROR, INFO ...@@ -28,9 +28,9 @@ from zLOG import LOG, ERROR, INFO
import sys import sys
class ActivityBuffer(TM): class ActivityBuffer(TM):
_p_oid=_p_changed=_registered=None _p_oid=_p_changed=_registered=None
def __init__(self): def __init__(self):
from thread import allocate_lock from thread import allocate_lock
self._use_TM = self._transactions = 1 self._use_TM = self._transactions = 1
...@@ -38,7 +38,7 @@ class ActivityBuffer(TM): ...@@ -38,7 +38,7 @@ class ActivityBuffer(TM):
self._tlock = allocate_lock() self._tlock = allocate_lock()
self._tthread = None self._tthread = None
self._lock = allocate_lock() self._lock = allocate_lock()
# Keeps a list of messages to add and remove # Keeps a list of messages to add and remove
# at end of transaction # at end of transaction
def _begin(self, *ignored): def _begin(self, *ignored):
...@@ -57,7 +57,7 @@ class ActivityBuffer(TM): ...@@ -57,7 +57,7 @@ class ActivityBuffer(TM):
error=sys.exc_info()) error=sys.exc_info())
self._tlock.release() self._tlock.release()
raise raise
def _finish(self, *ignored): def _finish(self, *ignored):
from thread import get_ident from thread import get_ident
if not self._tlock.locked() or self._tthread != get_ident(): if not self._tlock.locked() or self._tthread != get_ident():
...@@ -100,24 +100,34 @@ class ActivityBuffer(TM): ...@@ -100,24 +100,34 @@ class ActivityBuffer(TM):
for (activity, activity_tool, message) in self.flushed_activity: for (activity, activity_tool, message) in self.flushed_activity:
#LOG('ActivityBuffer prepareDeleteMessage', ERROR, str(message.method_id)) #LOG('ActivityBuffer prepareDeleteMessage', ERROR, str(message.method_id))
activity.prepareDeleteMessage(activity_tool, message) activity.prepareDeleteMessage(activity_tool, message)
activity_dict = {}
for (activity, activity_tool, message) in self.queued_activity: for (activity, activity_tool, message) in self.queued_activity:
#LOG('ActivityBuffer prepareQueueMessage', ERROR, str(message.method_id)) key = (activity, activity_tool)
activity.prepareQueueMessage(activity_tool, message) if key not in activity_dict:
activity_dict[key] = []
activity_dict[key].append(message)
for key, message_list in activity_dict.items():
activity, activity_tool = key
if hasattr(activity, 'prepareQueueMessageList'):
activity.prepareQueueMessageList(activity_tool, message_list)
else:
for message in message_list:
activity.prepareQueueMessage(activity_tool, message)
except: except:
LOG('ActivityBuffer', ERROR, "exception during tpc_prepare", LOG('ActivityBuffer', ERROR, "exception during tpc_prepare",
error=sys.exc_info()) error=sys.exc_info())
raise raise
def deferredQueueMessage(self, activity_tool, activity, message): def deferredQueueMessage(self, activity_tool, activity, message):
self._register() self._register()
# Activity is called to prevent queuing some messages (useful for example # Activity is called to prevent queuing some messages (useful for example
# to prevent reindexing objects multiple times) # to prevent reindexing objects multiple times)
if not activity.isMessageRegistered(self, activity_tool, message): if not activity.isMessageRegistered(self, activity_tool, message):
self.queued_activity.append((activity, activity_tool, message)) self.queued_activity.append((activity, activity_tool, message))
# We register queued messages so that we can # We register queued messages so that we can
# unregister them # unregister them
activity.registerMessage(self, activity_tool, message) activity.registerMessage(self, activity_tool, message)
def deferredDeleteMessage(self, activity_tool, activity, message): def deferredDeleteMessage(self, activity_tool, activity, message):
self._register() self._register()
self.flushed_activity.append((activity, activity_tool, message)) self.flushed_activity.append((activity, activity_tool, message))
......
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