Commit 2fa6bfeb authored by Vincent Pelletier's avatar Vincent Pelletier

Make registerMessage check for duplicate registration.

isMessageRegistered duplicates work done in registerMessage, so it wastes
time when creating an activity (in the likely event the activity is not a
duplicate).
parent 290a9b38
...@@ -239,16 +239,19 @@ class Queue(object): ...@@ -239,16 +239,19 @@ class Queue(object):
pass pass
def isMessageRegistered(self, activity_buffer, activity_tool, m): def isMessageRegistered(self, activity_buffer, activity_tool, m):
# BBB: deprecated
message_list = activity_buffer.getMessageList(self) message_list = activity_buffer.getMessageList(self)
return m in message_list return m in message_list
def registerMessage(self, activity_buffer, activity_tool, m): def registerMessage(self, activity_buffer, activity_tool, m):
message_list = activity_buffer.getMessageList(self) message_list = activity_buffer.getMessageList(self)
if m in message_list:
return
message_list.append(m) message_list.append(m)
m.is_registered = 1 m.is_registered = True
def unregisterMessage(self, activity_buffer, activity_tool, m): def unregisterMessage(self, activity_buffer, activity_tool, m):
m.is_registered = 0 m.is_registered = False
def getRegisteredMessageList(self, activity_buffer, activity_tool): def getRegisteredMessageList(self, activity_buffer, activity_tool):
message_list = activity_buffer.getMessageList(self) message_list = activity_buffer.getMessageList(self)
......
...@@ -96,17 +96,21 @@ class SQLDict(SQLBase): ...@@ -96,17 +96,21 @@ class SQLDict(SQLBase):
return (tuple(m.object_path), m.method_id, m.activity_kw.get('tag'), m.activity_kw.get('group_id')) return (tuple(m.object_path), m.method_id, m.activity_kw.get('tag'), m.activity_kw.get('group_id'))
def isMessageRegistered(self, activity_buffer, activity_tool, m): def isMessageRegistered(self, activity_buffer, activity_tool, m):
# BBB: deprecated
return self.generateMessageUID(m) in activity_buffer.getUidSet(self) return self.generateMessageUID(m) in activity_buffer.getUidSet(self)
def registerMessage(self, activity_buffer, activity_tool, m): def registerMessage(self, activity_buffer, activity_tool, m):
message_id = self.generateMessageUID(m)
uid_set = activity_buffer.getUidSet(self)
if message_id in uid_set:
return
uid_set.add(message_id)
message_list = activity_buffer.getMessageList(self) message_list = activity_buffer.getMessageList(self)
message_list.append(m) message_list.append(m)
uid_set = activity_buffer.getUidSet(self) m.is_registered = True
uid_set.add(self.generateMessageUID(m))
m.is_registered = 1
def unregisterMessage(self, activity_buffer, activity_tool, m): def unregisterMessage(self, activity_buffer, activity_tool, m):
m.is_registered = 0 # This prevents from inserting deleted messages into the queue m.is_registered = False # This prevents from inserting deleted messages into the queue
class_name = self.__class__.__name__ class_name = self.__class__.__name__
uid_set = activity_buffer.getUidSet(self) uid_set = activity_buffer.getUidSet(self)
uid_set.discard(self.generateMessageUID(m)) uid_set.discard(self.generateMessageUID(m))
......
...@@ -93,13 +93,10 @@ class ActivityBuffer(TM): ...@@ -93,13 +93,10 @@ class ActivityBuffer(TM):
def deferredQueueMessage(self, activity_tool, activity, message): def deferredQueueMessage(self, activity_tool, activity, message):
self._register(activity_tool) self._register(activity_tool)
# Activity is called to prevent queuing some messages (useful for example assert not message.is_registered, message
# to prevent reindexing objects multiple times) activity.registerMessage(self, activity_tool, message)
if not activity.isMessageRegistered(self, activity_tool, message): if message.is_registered:
self.queued_activity.append((activity, message)) self.queued_activity.append((activity, message))
# We register queued messages so that we can
# unregister them
activity.registerMessage(self, activity_tool, 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."""
......
...@@ -170,6 +170,7 @@ class Message(BaseMessage): ...@@ -170,6 +170,7 @@ class Message(BaseMessage):
processing = None processing = None
traceback = None traceback = None
oid = None oid = None
is_registered = False
def __init__(self, obj, active_process, activity_kw, method_id, args, kw, request=None, portal_activities=None): def __init__(self, obj, active_process, activity_kw, method_id, args, kw, request=None, portal_activities=None):
if isinstance(obj, str): if isinstance(obj, str):
......
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