From aeeb9336a6a5032bc0a4ed28e9ebde7adcbbc7ca Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Mon, 1 Jun 2026 15:22:01 +0300 Subject: [PATCH] Restrict initial sync profiles to local users for now We don't have federated profile updates (yet), so use a cheaper database call to fetch only local users for the initial sync. This mirrors incremental sync as currently there are only local profiles being pushed into the profile updates stream table. --- synapse/handlers/sync.py | 4 ++-- synapse/storage/databases/main/roommember.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index dc786f05da..029259e33c 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -2149,8 +2149,8 @@ class SyncHandler: sync_result_builder: profile_fields: The list of field IDs to filter for. """ - user_ids = await self.store.get_users_who_share_room_with_user(user_id) - user_ids = {u for u in user_ids if self._is_mine_id(u)} + # Currently, limited to only local profiles, so filter remote servers out + user_ids = await self.store.get_local_users_who_share_room_with_user(user_id) if not user_ids: return diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index 736f3e4c78..a645e4f3a5 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -982,6 +982,17 @@ class RoomMemberWorkerStore(EventsWorkerStore, CacheInvalidationWorkerStore): return user_who_share_room + async def get_local_users_who_share_room_with_user(self, user_id: str) -> set[str]: + """Returns the set of local users who share a room with `user_id`""" + room_ids = await self.get_rooms_for_user(user_id) + + user_who_share_room: set[str] = set() + for room_id in room_ids: + user_ids = await self.get_local_users_in_room(room_id) + user_who_share_room.update(user_ids) + + return user_who_share_room + @cached(cache_context=True, iterable=True) async def get_mutual_rooms_between_users( self, user_ids: frozenset[str], cache_context: _CacheContext