diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py index 778dddb400..7a734f6712 100644 --- a/synapse/handlers/sliding_sync.py +++ b/synapse/handlers/sliding_sync.py @@ -494,8 +494,7 @@ async def current_sync_for_user( # Assemble sliding window lists lists: Dict[str, SlidingSyncResult.SlidingWindowList] = {} - # Keep track of the rooms that we're going to display and need to fetch more - # info about + # Keep track of the rooms that we can display and need to fetch more info about relevant_room_map: Dict[str, RoomSyncConfig] = {} if has_lists and sync_config.lists is not None: sync_room_map = await self.filter_rooms_relevant_for_sync( @@ -623,6 +622,8 @@ async def current_sync_for_user( # Filter out rooms that haven't received updates and we've sent down # previously. + # Keep track of the rooms that we're going to display and need to fetch more info about + relevant_rooms_to_send_map = relevant_room_map if from_token: rooms_should_send = set() @@ -660,7 +661,7 @@ async def current_sync_for_user( relevant_room_map.keys(), from_token.stream_token.room_key ) rooms_should_send.update(rooms_that_have_updates) - relevant_room_map = { + relevant_rooms_to_send_map = { room_id: room_sync_config for room_id, room_sync_config in relevant_room_map.items() if room_id in rooms_should_send @@ -672,7 +673,7 @@ async def handle_room(room_id: str) -> None: room_sync_result = await self.get_room_sync_data( sync_config=sync_config, room_id=room_id, - room_sync_config=relevant_room_map[room_id], + room_sync_config=relevant_rooms_to_send_map[room_id], room_membership_for_user_at_to_token=room_membership_for_user_map[ room_id ], @@ -684,17 +685,19 @@ async def handle_room(room_id: str) -> None: if room_sync_result or not from_token: rooms[room_id] = room_sync_result - if relevant_room_map: + if relevant_rooms_to_send_map: with start_active_span("sliding_sync.generate_room_entries"): - await concurrently_execute(handle_room, relevant_room_map, 10) + await concurrently_execute(handle_room, relevant_rooms_to_send_map, 10) extensions = await self.get_extensions_response( sync_config=sync_config, actual_lists=lists, - # TODO: Once https://github.com/element-hq/synapse/pull/17479 merges, this - # will need to be updated to make sure it includes everything before the - # pre-filter on `relevant_room_map`. - actual_room_ids=set(rooms.keys()), + # We're purposely using `relevant_room_map` instead of + # `relevant_rooms_to_send_map` here. This needs to be all room_ids we could + # send regardless of whether they have an event update or not. The + # extensions care about more than just normal events in the rooms (like + # account data, read receipts, typing indicators, to-device messages, etc). + actual_room_ids=set(relevant_room_map.keys()), actual_room_response_map=rooms, from_token=from_token, to_token=to_token, @@ -704,7 +707,7 @@ async def handle_room(room_id: str) -> None: connection_position = await self.connection_store.record_rooms( sync_config=sync_config, from_token=from_token, - sent_room_ids=relevant_room_map.keys(), + sent_room_ids=relevant_rooms_to_send_map.keys(), # TODO: We need to calculate which rooms have had updates since the `from_token` but were not included in the `sent_room_ids` unsent_room_ids=[], ) diff --git a/tests/rest/client/test_sync.py b/tests/rest/client/test_sync.py index 9c3426b02c..1184adde70 100644 --- a/tests/rest/client/test_sync.py +++ b/tests/rest/client/test_sync.py @@ -6657,15 +6657,7 @@ def test_receipts_incremental_sync(self) -> None: exact=True, ) # No events in the timeline since they were sent before the `from_token` - self.assertIncludes( - { - event["event_id"] - for event in response_body["rooms"][room_id1].get("timeline", []) - }, - set(), - exact=True, - message=str(response_body["rooms"][room_id1]), - ) + self.assertNotIn(room_id1, response_body["rooms"]) # Check room3: # @@ -6694,15 +6686,7 @@ def test_receipts_incremental_sync(self) -> None: exact=True, ) # No events in the timeline since they were sent before the `from_token` - self.assertIncludes( - { - event["event_id"] - for event in response_body["rooms"][room_id3].get("timeline", []) - }, - set(), - exact=True, - message=str(response_body["rooms"][room_id3]), - ) + self.assertNotIn(room_id3, response_body["rooms"]) def test_receipts_incremental_sync_all_live_receipts(self) -> None: """