summary refs log tree commit diff
path: root/synapse/storage/databases/main/devices.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2023-03-29 14:37:06 +0100
committerGitHub <noreply@github.com>2023-03-29 13:37:06 +0000
commitf0d8f66eaaacfa75bed65bc5d0c602fbc5339c85 (patch)
treeec056eecace1f460480e0e7334287dc876d82cf4 /synapse/storage/databases/main/devices.py
parentRevert "Reintroduce membership tables event stream ordering (#15128)" (#15347) (diff)
downloadsynapse-f0d8f66eaaacfa75bed65bc5d0c602fbc5339c85.tar.xz
Fix registering a device on an account with lots of devices (#15348)
Fixes up #15183
Diffstat (limited to 'synapse/storage/databases/main/devices.py')
-rw-r--r--synapse/storage/databases/main/devices.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py

index 7647cda2c6..f61b7bc96e 100644 --- a/synapse/storage/databases/main/devices.py +++ b/synapse/storage/databases/main/devices.py
@@ -1638,19 +1638,22 @@ class DeviceBackgroundUpdateStore(SQLBaseStore): """ rows = await self.db_pool.execute( - "check_too_many_devices_for_user_last_seen", None, sql, (user_id,) + "check_too_many_devices_for_user_last_seen", + None, + sql, + user_id, ) if rows: max_last_seen = max(rows[0][0], max_last_seen) # Fetch the devices to delete. sql = """ - SELECT DISTINCT device_id FROM devices + SELECT device_id FROM devices LEFT JOIN e2e_device_keys_json USING (user_id, device_id) WHERE user_id = ? AND NOT hidden - AND last_seen < ? + AND last_seen <= ? AND key_json IS NULL ORDER BY last_seen """