summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@element.io>2024-01-10 13:55:16 +0000
committerGitHub <noreply@github.com>2024-01-10 13:55:16 +0000
commit4c67f0391ba6001aea37642935466bbbb145da7a (patch)
tree31c52f8a4e8db511b4593ec3c832202f9ba0bc25
parentFix auto-merge CI to correctly wait for linting. (#16781) (diff)
downloadsynapse-4c67f0391ba6001aea37642935466bbbb145da7a.tar.xz
Split up deleting devices into batches (#16766)
Otherwise for users with large numbers of devices this can cause a lot
of woe.
-rw-r--r--changelog.d/16766.misc1
-rw-r--r--synapse/storage/databases/main/devices.py8
2 files changed, 7 insertions, 2 deletions
diff --git a/changelog.d/16766.misc b/changelog.d/16766.misc
new file mode 100644
index 0000000000..ded77a11c4
--- /dev/null
+++ b/changelog.d/16766.misc
@@ -0,0 +1 @@
+Split up deleting devices into batches.
diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py
index 66fabf4f76..ae914298fb 100644
--- a/synapse/storage/databases/main/devices.py
+++ b/synapse/storage/databases/main/devices.py
@@ -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))