Skip to content

Commit

Permalink
Split up deleting devices into batches (#16766)
Browse files Browse the repository at this point in the history
Otherwise for users with large numbers of devices this can cause a lot
of woe.
  • Loading branch information
erikjohnston committed Jan 10, 2024
1 parent 72e9b74 commit 4c67f03
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/16766.misc
@@ -0,0 +1 @@
Split up deleting devices into batches.
8 changes: 6 additions & 2 deletions synapse/storage/databases/main/devices.py
Expand Up @@ -1794,7 +1794,7 @@ async def delete_devices(self, user_id: str, device_ids: List[str]) -> None:
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",
Expand All @@ -1811,7 +1811,11 @@ def _delete_devices_txn(txn: LoggingTransaction) -> None:
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))

Expand Down

0 comments on commit 4c67f03

Please sign in to comment.