Return an error when doing two purges on a room

Queuing up purges doesn't sound like a good thing.
This commit is contained in:
Richard van der Hoff 2018-03-07 17:32:46 +00:00
parent b984dd0b73
commit 1708412f56

View File

@ -50,15 +50,26 @@ class MessageHandler(BaseHandler):
self.clock = hs.get_clock() self.clock = hs.get_clock()
self.pagination_lock = ReadWriteLock() self.pagination_lock = ReadWriteLock()
self._purges_in_progress_by_room = set()
@defer.inlineCallbacks @defer.inlineCallbacks
def purge_history(self, room_id, topological_ordering, def purge_history(self, room_id, topological_ordering,
delete_local_events=False): delete_local_events=False):
with (yield self.pagination_lock.write(room_id)): if room_id in self._purges_in_progress_by_room:
yield self.store.purge_history( raise SynapseError(
room_id, topological_ordering, delete_local_events, 400,
"History purge already in progress for %s" % (room_id, ),
) )
self._purges_in_progress_by_room.add(room_id)
try:
with (yield self.pagination_lock.write(room_id)):
yield self.store.purge_history(
room_id, topological_ordering, delete_local_events,
)
finally:
self._purges_in_progress_by_room.discard(room_id)
@defer.inlineCallbacks @defer.inlineCallbacks
def get_messages(self, requester, room_id=None, pagin_config=None, def get_messages(self, requester, room_id=None, pagin_config=None,
as_client_event=True, event_filter=None): as_client_event=True, event_filter=None):