mirror of
https://github.com/element-hq/synapse.git
synced 2025-12-10 00:02:09 -05:00
Don't schedule an async task on every sync (#16312)
This commit is contained in:
parent
be3c7b08a3
commit
e9addf6a01
1
changelog.d/16312.misc
Normal file
1
changelog.d/16312.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Delete device messages asynchronously and in staged batches using the task scheduler.
|
||||||
@ -362,7 +362,22 @@ class SyncHandler:
|
|||||||
# (since we now know that the device has received them)
|
# (since we now know that the device has received them)
|
||||||
if since_token is not None:
|
if since_token is not None:
|
||||||
since_stream_id = since_token.to_device_key
|
since_stream_id = since_token.to_device_key
|
||||||
# Delete device messages asynchronously and in batches using the task scheduler
|
# Fast path: delete a limited number of to-device messages up front.
|
||||||
|
# We do this to avoid the overhead of scheduling a task for every
|
||||||
|
# sync.
|
||||||
|
device_deletion_limit = 100
|
||||||
|
deleted = await self.store.delete_messages_for_device(
|
||||||
|
sync_config.user.to_string(),
|
||||||
|
sync_config.device_id,
|
||||||
|
since_stream_id,
|
||||||
|
limit=device_deletion_limit,
|
||||||
|
)
|
||||||
|
logger.debug(
|
||||||
|
"Deleted %d to-device messages up to %d", deleted, since_stream_id
|
||||||
|
)
|
||||||
|
|
||||||
|
# If we hit the limit, schedule a background task to delete the rest.
|
||||||
|
if deleted >= device_deletion_limit:
|
||||||
await self._task_scheduler.schedule_task(
|
await self._task_scheduler.schedule_task(
|
||||||
DELETE_DEVICE_MSGS_TASK_NAME,
|
DELETE_DEVICE_MSGS_TASK_NAME,
|
||||||
resource_id=sync_config.device_id,
|
resource_id=sync_config.device_id,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user