From 73d2b2d03fe243b9abd09831fa0abce08052ebc3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 19 Aug 2024 09:09:40 +0100 Subject: [PATCH 1/4] Batch up fetching receipts --- synapse/handlers/sliding_sync.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py index 64b5acbe986..31059fa5894 100644 --- a/synapse/handlers/sliding_sync.py +++ b/synapse/handlers/sliding_sync.py @@ -2858,6 +2858,7 @@ async def get_account_data_extension_response( account_data_by_room_map=account_data_by_room_map, ) + @trace async def get_receipts_extension_response( self, sync_config: SlidingSyncConfig, @@ -2966,24 +2967,25 @@ async def get_receipts_extension_response( # from that room but we only want to include receipts for events # in the timeline to avoid bloating and blowing up the sync response # as the number of users in the room increases. (this behavior is part of the spec) - for room_id in initial_rooms: - room_result = actual_room_response_map.get(room_id) - if room_result is None: - continue - - relevant_event_ids = [ - event.event_id for event in room_result.timeline_events - ] - - # TODO: In the future, it would be good to fetch less receipts - # out of the database in the first place but we would need to - # add a new `event_id` index to `receipts_linearized`. - initial_receipts = await self.store.get_linearized_receipts_for_room( - room_id=room_id, + initial_rooms = [ + room_id + for room_id in initial_rooms + if room_id in actual_room_response_map + ] + if initial_rooms: + initial_receipts = await self.store.get_linearized_receipts_for_rooms( + room_ids=initial_rooms, to_key=to_token.receipt_key, ) for receipt in initial_receipts: + relevant_event_ids = [ + event.event_id + for event in actual_room_response_map[ + receipt["room_id"] + ].timeline_events + ] + content = { event_id: content_value for event_id, content_value in receipt["content"].items() From 9e1d90b6a0967f0321a345c697405f66987a23f0 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 20 Aug 2024 09:14:12 +0100 Subject: [PATCH 2/4] Newsfile --- changelog.d/17589.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17589.misc diff --git a/changelog.d/17589.misc b/changelog.d/17589.misc new file mode 100644 index 00000000000..1b4a53ee178 --- /dev/null +++ b/changelog.d/17589.misc @@ -0,0 +1 @@ +Correctly track read receipts that should be sent down in experimental sliding sync. From bbe94c2337a605799b7c762acb2bb182e3474d15 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 20 Aug 2024 09:20:07 +0100 Subject: [PATCH 3/4] Fix linting --- synapse/handlers/sliding_sync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py index 31059fa5894..c760fde05a0 100644 --- a/synapse/handlers/sliding_sync.py +++ b/synapse/handlers/sliding_sync.py @@ -2967,11 +2967,11 @@ async def get_receipts_extension_response( # from that room but we only want to include receipts for events # in the timeline to avoid bloating and blowing up the sync response # as the number of users in the room increases. (this behavior is part of the spec) - initial_rooms = [ + initial_rooms = { room_id for room_id in initial_rooms if room_id in actual_room_response_map - ] + } if initial_rooms: initial_receipts = await self.store.get_linearized_receipts_for_rooms( room_ids=initial_rooms, From 0c71d06bf4209b7966b2f7ed67aab94c3a4388a7 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 20 Aug 2024 09:48:42 +0100 Subject: [PATCH 4/4] use a set --- synapse/handlers/sliding_sync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py index c760fde05a0..c6834a1036b 100644 --- a/synapse/handlers/sliding_sync.py +++ b/synapse/handlers/sliding_sync.py @@ -2979,12 +2979,12 @@ async def get_receipts_extension_response( ) for receipt in initial_receipts: - relevant_event_ids = [ + relevant_event_ids = { event.event_id for event in actual_room_response_map[ receipt["room_id"] ].timeline_events - ] + } content = { event_id: content_value