Limit the number of devices we delete at once (#14649)

This commit is contained in:
Erik Johnston 2022-12-09 13:31:32 +00:00 committed by GitHub
parent c2de2ca630
commit 94bc21e69f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 4 deletions

View file

@ -458,10 +458,12 @@ class DeviceHandler(DeviceWorkerHandler):
async def _prune_too_many_devices(self, user_id: str) -> None:
"""Delete any excess old devices this user may have."""
device_ids = await self.store.check_too_many_devices_for_user(user_id)
device_ids = await self.store.check_too_many_devices_for_user(user_id, 100)
if not device_ids:
return
logger.info("Pruning %d old devices for user %s", len(device_ids), user_id)
# We don't want to block and try and delete tonnes of devices at once,
# so we cap the number of devices we delete synchronously.
first_batch, remaining_device_ids = device_ids[:10], device_ids[10:]