Delete completes to-device messages earlier in /sync (#10124)

I hope this will improve
https://github.com/matrix-org/synapse/issues/9564.
This commit is contained in:
Richard van der Hoff 2021-06-07 09:19:06 +01:00 committed by GitHub
parent a0cd8ae8cb
commit fa1db8f156
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

1
changelog.d/10124.misc Normal file
View file

@ -0,0 +1 @@
Work to improve the responsiveness of `/sync` requests.

View file

@ -315,6 +315,17 @@ class SyncHandler:
if context: if context:
context.tag = sync_type context.tag = sync_type
# if we have a since token, delete any to-device messages before that token
# (since we now know that the device has received them)
if since_token is not None:
since_stream_id = since_token.to_device_key
deleted = await self.store.delete_messages_for_device(
sync_config.user.to_string(), sync_config.device_id, since_stream_id
)
logger.debug(
"Deleted %d to-device messages up to %d", deleted, since_stream_id
)
if timeout == 0 or since_token is None or full_state: if timeout == 0 or since_token is None or full_state:
# we are going to return immediately, so don't bother calling # we are going to return immediately, so don't bother calling
# notifier.wait_for_events. # notifier.wait_for_events.
@ -1230,16 +1241,6 @@ class SyncHandler:
since_stream_id = int(sync_result_builder.since_token.to_device_key) since_stream_id = int(sync_result_builder.since_token.to_device_key)
if since_stream_id != int(now_token.to_device_key): if since_stream_id != int(now_token.to_device_key):
# We only delete messages when a new message comes in, but that's
# fine so long as we delete them at some point.
deleted = await self.store.delete_messages_for_device(
user_id, device_id, since_stream_id
)
logger.debug(
"Deleted %d to-device messages up to %d", deleted, since_stream_id
)
messages, stream_id = await self.store.get_new_messages_for_device( messages, stream_id = await self.store.get_new_messages_for_device(
user_id, device_id, since_stream_id, now_token.to_device_key user_id, device_id, since_stream_id, now_token.to_device_key
) )