From e09a2c0e0f15dcbcd7f75f4b497c2dbc3d918d5a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 25 Jul 2025 18:21:03 +0000 Subject: [PATCH] Window sync ranges below any partially completed writes. Signed-off-by: Jason Volk --- src/api/client/sync/v3.rs | 11 +++++++---- src/api/client/sync/v5.rs | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/api/client/sync/v3.rs b/src/api/client/sync/v3.rs index 58a96796..09cccfdc 100644 --- a/src/api/client/sync/v3.rs +++ b/src/api/client/sync/v3.rs @@ -133,7 +133,8 @@ pub(crate) async fn sync_events_route( // Setup watchers, so if there's no response, we can wait for them let watcher = services.sync.watch(sender_user, sender_device); - let response = build_sync_events(&services, &body).await?; + let next_batch = services.globals.current_count(); + let response = build_sync_events(&services, &body, next_batch).await?; if body.body.full_state || !(response.rooms.is_empty() && response.presence.is_empty() @@ -147,20 +148,22 @@ pub(crate) async fn sync_events_route( // Hang a few seconds so requests are not spammed // Stop hanging if new info arrives let default = Duration::from_secs(30); - let duration = cmp::min(body.body.timeout.unwrap_or(default), default); + let timeout = body.body.timeout.unwrap_or(default); + let duration = cmp::min(timeout, default); _ = tokio::time::timeout(duration, watcher).await; // Retry returning data - build_sync_events(&services, &body).await + let next_batch = services.globals.current_count(); + build_sync_events(&services, &body, next_batch).await } pub(crate) async fn build_sync_events( services: &Services, body: &Ruma, + next_batch: u64, ) -> Result> { let (sender_user, sender_device) = body.sender(); - let next_batch = services.globals.current_count(); let since = body .body .since diff --git a/src/api/client/sync/v5.rs b/src/api/client/sync/v5.rs index fb3a97cd..6d29e836 100644 --- a/src/api/client/sync/v5.rs +++ b/src/api/client/sync/v5.rs @@ -87,7 +87,7 @@ pub(crate) async fn sync_events_v5_route( // Setup watchers, so if there's no response, we can wait for them let watcher = services.sync.watch(sender_user, sender_device); - let next_batch = services.globals.next_count(); + let next_batch = services.globals.current_count(); // Get sticky parameters from cache let mut cached = body.body.clone();