From fd596d175fc02a38049be058178b01c2c8c79e17 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 26 Apr 2022 15:58:27 +0100 Subject: [PATCH 1/3] Mark remote device list updates as already handled We don't bother caclulating outbound pokes for remote device list updates, so we shouldn't mark them as needing to be handled by the `_handle_new_device_update_async` background job. --- synapse/handlers/device.py | 5 +++-- synapse/storage/databases/main/devices.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/device.py b/synapse/handlers/device.py index 319836da2bee..a91b1ee4d5f4 100644 --- a/synapse/handlers/device.py +++ b/synapse/handlers/device.py @@ -505,8 +505,9 @@ async def notify_device_update( "device_list_key", position, users={user_id}, rooms=room_ids ) - # We may need to do some processing asynchronously. - self._handle_new_device_update_async() + # We may need to do some processing asynchronously for local user IDs. + if self.hs.is_mine_id(user_id): + self._handle_new_device_update_async() async def notify_user_signature_update( self, from_user_id: str, user_ids: List[str] diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py index 59d223a9008c..483dd804067a 100644 --- a/synapse/storage/databases/main/devices.py +++ b/synapse/storage/databases/main/devices.py @@ -1748,7 +1748,8 @@ def _add_device_outbound_room_poke_txn( device_id, room_id, stream_id, - False, + # We only need to calculate outbound pokes for local users + not self.hs.is_mine_id(user_id), encoded_context, ) for room_id in room_ids From f5636144323aad37be7b6f0a715c79b76d4142ca Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 26 Apr 2022 16:02:56 +0100 Subject: [PATCH 2/3] Newsfile --- changelog.d/12557.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12557.misc diff --git a/changelog.d/12557.misc b/changelog.d/12557.misc new file mode 100644 index 000000000000..e4eb895ef5cb --- /dev/null +++ b/changelog.d/12557.misc @@ -0,0 +1 @@ +Reduce unnecessary work when handling remote device list updates. From 7493730dc932f1ec425ab3cd00a12950a8d44b1d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 26 Apr 2022 16:24:19 +0100 Subject: [PATCH 3/3] Fix tests --- tests/storage/test_devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/storage/test_devices.py b/tests/storage/test_devices.py index ccc3893869db..bbf079b25b59 100644 --- a/tests/storage/test_devices.py +++ b/tests/storage/test_devices.py @@ -29,7 +29,7 @@ def add_device_change(self, user_id, device_ids, host): for device_id in device_ids: stream_id = self.get_success( self.store.add_device_change_to_streams( - "user_id", [device_id], ["!some:room"] + user_id, [device_id], ["!some:room"] ) )