From 9bcb49ea48ae5f26a6ffa3d1eddf25826a76df7e Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 18 Aug 2020 09:23:44 -0400 Subject: [PATCH] Fix the return type of send_nonmember_events. --- changelog.d/8112.misc | 1 + synapse/handlers/message.py | 2 +- synapse/storage/databases/main/stream.py | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 changelog.d/8112.misc diff --git a/changelog.d/8112.misc b/changelog.d/8112.misc new file mode 100644 index 000000000000..80045dde1af1 --- /dev/null +++ b/changelog.d/8112.misc @@ -0,0 +1 @@ +Return the previous stream token if a non-member event is a duplicate. diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index f242d3c6acb7..532fc30681b0 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -674,7 +674,7 @@ async def send_nonmember_event( event.event_id, prev_event.event_id, ) - return await self.store.get_stream_token_for_event(prev_event.event_id) + return await self.store.get_stream_id_for_event(prev_event.event_id) return await self.handle_new_client_event( requester=requester, event=event, context=context, ratelimit=ratelimit diff --git a/synapse/storage/databases/main/stream.py b/synapse/storage/databases/main/stream.py index 8ccfb8fc46f6..4377bddb8cae 100644 --- a/synapse/storage/databases/main/stream.py +++ b/synapse/storage/databases/main/stream.py @@ -582,6 +582,19 @@ async def get_room_events_max_id(self, room_id: Optional[str] = None) -> str: ) return "t%d-%d" % (topo, token) + async def get_stream_id_for_event(self, event_id: str) -> int: + """The stream ID for an event + Args: + event_id: The id of the event to look up a stream token for. + Raises: + StoreError if the event wasn't in the database. + Returns: + A stream ID. + """ + return await self.db_pool.simple_select_one_onecol( + table="events", keyvalues={"event_id": event_id}, retcol="stream_ordering" + ) + async def get_stream_token_for_event(self, event_id: str) -> str: """The stream token for an event Args: @@ -591,10 +604,8 @@ async def get_stream_token_for_event(self, event_id: str) -> str: Returns: A "s%d" stream token. """ - row = await self.db_pool.simple_select_one_onecol( - table="events", keyvalues={"event_id": event_id}, retcol="stream_ordering" - ) - return "s%d" % (row,) + stream_id = await self.get_stream_id_for_event(event_id) + return "s%d" % (stream_id,) async def get_topological_token_for_event(self, event_id: str) -> str: """The stream token for an event