diff --git a/src/api/client/sync/v5.rs b/src/api/client/sync/v5.rs index 4a305c8a..1132e7f0 100644 --- a/src/api/client/sync/v5.rs +++ b/src/api/client/sync/v5.rs @@ -130,25 +130,22 @@ pub(crate) async fn sync_events_v5_route( let (mut conn, _) = join(conn, ping_presence).await; - // The client must either use the last returned next_batch or replay the - // next_batch from the penultimate request: it's either up-to-date or - // one-behind. If we receive anything else we can boot them. let advancing = since == conn.next_batch; - let replaying = since == conn.globalsince; - if !advancing && !replaying { + let retarding = since <= conn.globalsince; + if !advancing && !retarding { return Err!(Request(UnknownPos("Requesting unknown or stale stream position."))); } debug_assert!( - advancing || replaying, - "Request should either be advancing or replaying the last request." + advancing || retarding, + "Request should either be advancing or replaying the since token." ); // Update parameters regardless of replay or advance conn.next_batch = services.globals.wait_pending().await?; conn.globalsince = since.min(conn.next_batch); conn.update_cache(request); - conn.update_rooms_prologue(advancing); + conn.update_rooms_prologue(retarding.then_some(since)); let mut response = Response { txn_id: request.txn_id.clone(), diff --git a/src/service/sync/mod.rs b/src/service/sync/mod.rs index 9c9ea503..e74360f6 100644 --- a/src/service/sync/mod.rs +++ b/src/service/sync/mod.rs @@ -53,8 +53,6 @@ pub struct Connection { #[derive(Clone, Copy, Debug, Default)] pub struct Room { pub roomsince: u64, - pub last_batch: u64, - pub next_batch: u64, } type Connections = StdMutex>; @@ -94,14 +92,12 @@ impl crate::Service for Service { } #[implement(Connection)] -pub fn update_rooms_prologue(&mut self, advance: bool) { +pub fn update_rooms_prologue(&mut self, retard_since: Option) { self.rooms.values_mut().for_each(|room| { - if advance { - room.roomsince = room.next_batch; - room.last_batch = room.next_batch; - } else { - room.roomsince = room.last_batch; - room.next_batch = room.last_batch; + if let Some(retard_since) = retard_since { + if room.roomsince > retard_since { + room.roomsince = retard_since; + } } }); } @@ -115,7 +111,6 @@ where let room = self.rooms.entry(room_id.into()).or_default(); room.roomsince = self.next_batch; - room.next_batch = self.next_batch; }); }