Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Split up deleting devices into batches #16766

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/16766.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Split up deleting devices into batches.
8 changes: 6 additions & 2 deletions synapse/storage/databases/main/devices.py
Original file line number Diff line number Diff line change
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