From bae06670661ada619f9a72c0ee4dcad2621c9dd4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 20 Nov 2024 19:42:34 +0000 Subject: [PATCH] limit sync response events to within the since/next_batch window fixes #606 Signed-off-by: Jason Volk --- src/api/client/sync/mod.rs | 6 ++++-- src/api/client/sync/v3.rs | 3 ++- src/api/client/sync/v4.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/client/sync/mod.rs b/src/api/client/sync/mod.rs index 3201b827..a9715b84 100644 --- a/src/api/client/sync/mod.rs +++ b/src/api/client/sync/mod.rs @@ -9,7 +9,8 @@ pub(crate) use self::{v3::sync_events_route, v4::sync_events_v4_route}; use crate::{service::Services, Error, PduEvent, Result}; async fn load_timeline( - services: &Services, sender_user: &UserId, room_id: &RoomId, roomsincecount: PduCount, limit: usize, + services: &Services, sender_user: &UserId, room_id: &RoomId, roomsincecount: PduCount, + next_batch: Option, limit: usize, ) -> Result<(Vec<(PduCount, PduEvent)>, bool), Error> { let last_timeline_count = services .rooms @@ -26,7 +27,8 @@ async fn load_timeline( .timeline .pdus_rev(Some(sender_user), room_id, None) .await? - .ready_take_while(|(pducount, _)| *pducount > roomsincecount); + .ready_skip_while(|&(pducount, _)| pducount > next_batch.unwrap_or_else(PduCount::max)) + .ready_take_while(|&(pducount, _)| pducount > roomsincecount); // Take the last events for the timeline let timeline_pdus: Vec<_> = non_timeline_pdus diff --git a/src/api/client/sync/v3.rs b/src/api/client/sync/v3.rs index 77ba4c3f..7a78ea74 100644 --- a/src/api/client/sync/v3.rs +++ b/src/api/client/sync/v3.rs @@ -540,7 +540,8 @@ async fn load_joined_room( let insert_lock = services.rooms.timeline.mutex_insert.lock(room_id).await; drop(insert_lock); - let (timeline_pdus, limited) = load_timeline(services, sender_user, room_id, sincecount, 10_usize).await?; + let (timeline_pdus, limited) = + load_timeline(services, sender_user, room_id, sincecount, Some(next_batchcount), 10_usize).await?; let send_notification_counts = !timeline_pdus.is_empty() || services diff --git a/src/api/client/sync/v4.rs b/src/api/client/sync/v4.rs index 91abd24e..57edc953 100644 --- a/src/api/client/sync/v4.rs +++ b/src/api/client/sync/v4.rs @@ -473,7 +473,7 @@ pub(crate) async fn sync_events_v4_route( (timeline_pdus, limited) = (Vec::new(), true); } else { (timeline_pdus, limited) = - match load_timeline(&services, sender_user, room_id, roomsincecount, *timeline_limit).await { + match load_timeline(&services, sender_user, room_id, roomsincecount, None, *timeline_limit).await { Ok(value) => value, Err(err) => { warn!("Encountered missing timeline in {}, error {}", room_id, err);