From 22eb20647e9b2ba0aafe3f5c3d921e6628eab03b Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 12 Oct 2020 14:34:39 +0100 Subject: [PATCH] Comments --- synapse/handlers/room_member.py | 3 +++ synapse/storage/persist_events.py | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index dd05114908..e196e95923 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -171,6 +171,9 @@ class RoomMemberHandler(metaclass=abc.ABCMeta): if requester.is_guest: content["kind"] = "guest" + # Check if we already have an event with a matching transaction ID. (We + # do this check just before we persist an event as well, but may as well + # do it up front for efficiency.) if txn_id and requester.access_token_id: existing_event_id = await self.store.get_event_id_from_transaction_id( requester.user.to_string(), requester.access_token_id, txn_id, diff --git a/synapse/storage/persist_events.py b/synapse/storage/persist_events.py index b0afa7132d..70e636b0ba 100644 --- a/synapse/storage/persist_events.py +++ b/synapse/storage/persist_events.py @@ -96,7 +96,9 @@ class _EventPeristenceQueue: Returns: defer.Deferred: a deferred which will resolve once the events are - persisted. Runs its callbacks *without* a logcontext. + persisted. Runs its callbacks *without* a logcontext. The result + is the same as that returned by the callback passed to + `handle_queue`. """ queue = self._event_persist_queues.setdefault(room_id, deque()) if queue: @@ -229,7 +231,7 @@ class EventsPersistenceStorage: for room_id in partitioned: self._maybe_start_persisting(room_id) - # The deferred returns a map from event ID to existing event ID if the + # Each deferred returns a map from event ID to existing event ID if the # event was deduplicated. (The dict may also include other entries if # the event was persisted in a batch with other events). # @@ -324,7 +326,8 @@ class EventsPersistenceStorage: # # We should have checked this a long time before we get here, but it's # possible that different send event requests race in such a way that - # they both pass the earlier checks. + # they both pass the earlier checks. Checking here isn't racey as we can + # have only one `_persist_events` per room being called at a time. replaced_events = await self.main_store.get_already_persisted_events( (event for event, _ in events_and_contexts) )