diff options
-rw-r--r-- | synapse/handlers/sliding_sync.py | 25 | ||||
-rw-r--r-- | tests/rest/client/test_sync.py | 3 |
2 files changed, 26 insertions, 2 deletions
diff --git a/synapse/handlers/sliding_sync.py b/synapse/handlers/sliding_sync.py index 6d0d9b425c..da0aca379f 100644 --- a/synapse/handlers/sliding_sync.py +++ b/synapse/handlers/sliding_sync.py @@ -601,6 +601,31 @@ class SlidingSyncHandler: else: relevant_room_map[room_id] = room_sync_config + # Filter out rooms that haven't received updates and we've sent down + # previously. + if from_token: + rooms_should_send = set() + for room_id in relevant_room_map: + status = await self.connection_store.have_sent_room( + user_id, + sync_config.connection_id(), + from_token.connection_token, + room_id, + ) + if status.status != HaveSentRoomFlag.LIVE: + rooms_should_send.add(room_id) + + # TODO: Also check current state delta stream + rooms_that_have_updates = ( + self.store._events_stream_cache.get_entities_changed( + relevant_room_map, from_token.stream_token.room_key.stream + ) + ) + rooms_should_send.update(rooms_that_have_updates) + relevant_room_map = { + r: c for r, c in relevant_room_map.items() if r in rooms_should_send + } + # Fetch room data rooms: Dict[str, SlidingSyncResult.RoomResult] = {} for room_id, room_sync_config in relevant_room_map.items(): diff --git a/tests/rest/client/test_sync.py b/tests/rest/client/test_sync.py index ada95bba22..0c66111e07 100644 --- a/tests/rest/client/test_sync.py +++ b/tests/rest/client/test_sync.py @@ -3569,8 +3569,7 @@ class SlidingSyncTestCase(unittest.HomeserverTestCase): # We only return updates but only if we've sent the room down the # connection before. - self.assertIsNone(channel.json_body["rooms"][room_id1].get("required_state")) - self.assertIsNone(channel.json_body["rooms"][room_id1].get("invite_state")) + self.assertNotIn(room_id1, channel.json_body["rooms"]) def test_rooms_required_state_wildcard(self) -> None: """ |