diff options
author | Richard van der Hoff <richard@matrix.org> | 2018-03-07 17:32:46 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2018-03-12 16:22:54 +0000 |
commit | 1708412f569dc28931a3704d679b41b92ac788b9 (patch) | |
tree | 3f8328d884b8afacd41e1d1332f76244383ce1e0 | |
parent | Merge pull request #2961 from matrix-org/rav/run_in_background (diff) | |
download | synapse-1708412f569dc28931a3704d679b41b92ac788b9.tar.xz |
Return an error when doing two purges on a room
Queuing up purges doesn't sound like a good thing.
Diffstat (limited to '')
-rw-r--r-- | synapse/handlers/message.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index dd00d8a86c..6eb8d19dc9 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -50,15 +50,26 @@ class MessageHandler(BaseHandler): self.clock = hs.get_clock() self.pagination_lock = ReadWriteLock() + self._purges_in_progress_by_room = set() @defer.inlineCallbacks def purge_history(self, room_id, topological_ordering, delete_local_events=False): - with (yield self.pagination_lock.write(room_id)): - yield self.store.purge_history( - room_id, topological_ordering, delete_local_events, + if room_id in self._purges_in_progress_by_room: + raise SynapseError( + 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 def get_messages(self, requester, room_id=None, pagin_config=None, as_client_event=True, event_filter=None): |