From de955293cf86dd075c6d5080670b144561a751e3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 30 Sep 2024 12:59:50 +0100 Subject: [PATCH] Add fast path for sliding sync streams that only ask for extensions (#17768) Principally useful for EX e2ee sliding sync connections. --- changelog.d/17768.misc | 1 + synapse/handlers/sliding_sync/room_lists.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 changelog.d/17768.misc diff --git a/changelog.d/17768.misc b/changelog.d/17768.misc new file mode 100644 index 00000000000..3b80e725341 --- /dev/null +++ b/changelog.d/17768.misc @@ -0,0 +1 @@ +Improve performance of sliding sync connections that do not ask for any rooms. diff --git a/synapse/handlers/sliding_sync/room_lists.py b/synapse/handlers/sliding_sync/room_lists.py index 0c9722021ae..08e619042b7 100644 --- a/synapse/handlers/sliding_sync/room_lists.py +++ b/synapse/handlers/sliding_sync/room_lists.py @@ -123,6 +123,19 @@ class SlidingSyncInterestedRooms: newly_left_rooms: AbstractSet[str] dm_room_ids: AbstractSet[str] + @staticmethod + def empty() -> "SlidingSyncInterestedRooms": + return SlidingSyncInterestedRooms( + lists={}, + relevant_room_map={}, + relevant_rooms_to_send_map={}, + all_rooms=set(), + room_membership_for_user_map={}, + newly_joined_rooms=set(), + newly_left_rooms=set(), + dm_room_ids=set(), + ) + def filter_membership_for_sync( *, @@ -181,6 +194,14 @@ async def compute_interested_rooms( from_token: Optional[StreamToken], ) -> SlidingSyncInterestedRooms: """Fetch the set of rooms that match the request""" + has_lists = sync_config.lists is not None and len(sync_config.lists) > 0 + has_room_subscriptions = ( + sync_config.room_subscriptions is not None + and len(sync_config.room_subscriptions) > 0 + ) + + if not has_lists and not has_room_subscriptions: + return SlidingSyncInterestedRooms.empty() if await self.store.have_finished_sliding_sync_background_jobs(): return await self._compute_interested_rooms_new_tables(