diff options
author | Erik Johnston <erikj@element.io> | 2024-05-16 16:07:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-16 16:07:54 +0100 |
commit | fd1200344112eb28486ee6f82ee341ada8bb4f06 (patch) | |
tree | 80a5085a9f2eb85025fe3467ec642ea3b3360ab8 /synapse/handlers/sync.py | |
parent | Fix bug where push rules would be empty in `/sync` (#17142) (diff) | |
download | synapse-fd1200344112eb28486ee6f82ee341ada8bb4f06.tar.xz |
Revert "Improve perf of sync device lists" (#17207)
Reverts element-hq/synapse#17191
Diffstat (limited to 'synapse/handlers/sync.py')
-rw-r--r-- | synapse/handlers/sync.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 659499af75..2bd1b8de88 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -1854,13 +1854,38 @@ class SyncHandler: # Step 1a, check for changes in devices of users we share a room # with - users_that_have_changed = ( - await self._device_handler.get_device_changes_in_shared_rooms( - user_id, - sync_result_builder.joined_room_ids, - from_token=since_token, - ) + # + # We do this in two different ways depending on what we have cached. + # If we already have a list of all the user that have changed since + # the last sync then it's likely more efficient to compare the rooms + # they're in with the rooms the syncing user is in. + # + # If we don't have that info cached then we get all the users that + # share a room with our user and check if those users have changed. + cache_result = self.store.get_cached_device_list_changes( + since_token.device_list_key ) + if cache_result.hit: + changed_users = cache_result.entities + + result = await self.store.get_rooms_for_users(changed_users) + + for changed_user_id, entries in result.items(): + # Check if the changed user shares any rooms with the user, + # or if the changed user is the syncing user (as we always + # want to include device list updates of their own devices). + if user_id == changed_user_id or any( + rid in joined_rooms for rid in entries + ): + users_that_have_changed.add(changed_user_id) + else: + users_that_have_changed = ( + await self._device_handler.get_device_changes_in_shared_rooms( + user_id, + sync_result_builder.joined_room_ids, + from_token=since_token, + ) + ) # Step 1b, check for newly joined rooms for room_id in newly_joined_rooms: |