mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 12:33:49 +01:00
Speed up deleting to-device messages task (#16318)
This commit is contained in:
parent
39dc5de399
commit
e9e2904eb2
2 changed files with 15 additions and 13 deletions
1
changelog.d/16318.misc
Normal file
1
changelog.d/16318.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Speed up task to delete to-device messages.
|
|
@ -388,7 +388,8 @@ class DeviceWorkerHandler:
|
||||||
"Trying handling device list state for partial join: not supported on workers."
|
"Trying handling device list state for partial join: not supported on workers."
|
||||||
)
|
)
|
||||||
|
|
||||||
DEVICE_MSGS_DELETE_BATCH_LIMIT = 100
|
DEVICE_MSGS_DELETE_BATCH_LIMIT = 1000
|
||||||
|
DEVICE_MSGS_DELETE_SLEEP_MS = 1000
|
||||||
|
|
||||||
async def _delete_device_messages(
|
async def _delete_device_messages(
|
||||||
self,
|
self,
|
||||||
|
@ -400,19 +401,19 @@ class DeviceWorkerHandler:
|
||||||
device_id = task.params["device_id"]
|
device_id = task.params["device_id"]
|
||||||
up_to_stream_id = task.params["up_to_stream_id"]
|
up_to_stream_id = task.params["up_to_stream_id"]
|
||||||
|
|
||||||
res = await self.store.delete_messages_for_device(
|
# Delete the messages in batches to avoid too much DB load.
|
||||||
user_id=user_id,
|
while True:
|
||||||
device_id=device_id,
|
res = await self.store.delete_messages_for_device(
|
||||||
up_to_stream_id=up_to_stream_id,
|
user_id=user_id,
|
||||||
limit=DeviceHandler.DEVICE_MSGS_DELETE_BATCH_LIMIT,
|
device_id=device_id,
|
||||||
)
|
up_to_stream_id=up_to_stream_id,
|
||||||
|
limit=DeviceHandler.DEVICE_MSGS_DELETE_BATCH_LIMIT,
|
||||||
|
)
|
||||||
|
|
||||||
if res < DeviceHandler.DEVICE_MSGS_DELETE_BATCH_LIMIT:
|
if res < DeviceHandler.DEVICE_MSGS_DELETE_BATCH_LIMIT:
|
||||||
return TaskStatus.COMPLETE, None, None
|
return TaskStatus.COMPLETE, None, None
|
||||||
else:
|
|
||||||
# There is probably still device messages to be deleted, let's keep the task active and it will be run
|
await self.clock.sleep(DeviceHandler.DEVICE_MSGS_DELETE_SLEEP_MS / 1000.0)
|
||||||
# again in a subsequent scheduler loop run (probably the next one, if not too many tasks are running).
|
|
||||||
return TaskStatus.ACTIVE, None, None
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceHandler(DeviceWorkerHandler):
|
class DeviceHandler(DeviceWorkerHandler):
|
||||||
|
|
Loading…
Reference in a new issue