0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2025-01-19 06:52:03 +01:00

Split up deleting devices into batches (#16766)

Otherwise for users with large numbers of devices this can cause a lot
of woe.
This commit is contained in:
Erik Johnston 2024-01-10 13:55:16 +00:00 committed by GitHub
parent 72e9b74bbf
commit 4c67f0391b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

1
changelog.d/16766.misc Normal file
View file

@ -0,0 +1 @@
Split up deleting devices into batches.

View file

@ -1794,7 +1794,7 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
device_ids: The IDs of the devices to delete
"""
def _delete_devices_txn(txn: LoggingTransaction) -> None:
def _delete_devices_txn(txn: LoggingTransaction, device_ids: List[str]) -> None:
self.db_pool.simple_delete_many_txn(
txn,
table="devices",
@ -1811,7 +1811,11 @@ class DeviceStore(DeviceWorkerStore, DeviceBackgroundUpdateStore):
keyvalues={"user_id": user_id},
)
await self.db_pool.runInteraction("delete_devices", _delete_devices_txn)
for batch in batch_iter(device_ids, 100):
await self.db_pool.runInteraction(
"delete_devices", _delete_devices_txn, batch
)
for device_id in device_ids:
self.device_id_exists_cache.invalidate((user_id, device_id))