Skip to content

Commit 59449bc

Browse files
committed
feat(sdk) Remove delta_token from sliding sync.
Simplified sliding sync doesn't have `delta_token`. This patch removes it. Note: even the current sliding sync proxy doesn't use it.
1 parent 7279824 commit 59449bc

File tree

3 files changed

+14
-45
lines changed

3 files changed

+14
-45
lines changed

crates/matrix-sdk/src/sliding_sync/builder.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,17 @@ impl SlidingSyncBuilder {
255255
let restored_fields =
256256
restore_sliding_sync_state(&client, &self.storage_key, &lists).await?;
257257

258-
let (delta_token, pos) = if let Some(fields) = restored_fields {
258+
let pos = if let Some(fields) = restored_fields {
259259
#[cfg(feature = "e2e-encryption")]
260-
let pos = if self.share_pos { fields.pos } else { None };
260+
if self.share_pos {
261+
fields.pos
262+
} else {
263+
None
264+
}
261265
#[cfg(not(feature = "e2e-encryption"))]
262-
let pos = None;
263-
264-
(fields.delta_token, pos)
266+
None
265267
} else {
266-
(None, None)
268+
None
267269
};
268270

269271
#[cfg(feature = "e2e-encryption")]
@@ -289,7 +291,7 @@ impl SlidingSyncBuilder {
289291
lists,
290292
rooms,
291293

292-
position: Arc::new(AsyncMutex::new(SlidingSyncPositionMarkers { pos, delta_token })),
294+
position: Arc::new(AsyncMutex::new(SlidingSyncPositionMarkers { pos })),
293295
// SAFETY: `unwrap` is safe because 20 is not zero.
294296
past_positions: StdRwLock::new(RingBuffer::new(NonZeroUsize::new(20).unwrap())),
295297

crates/matrix-sdk/src/sliding_sync/cache.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ pub(super) async fn store_sliding_sync_state(
8888
storage
8989
.set_custom_value(
9090
instance_storage_key.as_bytes(),
91-
serde_json::to_vec(&FrozenSlidingSync::new(
92-
position,
93-
&*sliding_sync.inner.rooms.read().await,
94-
))?,
91+
serde_json::to_vec(&FrozenSlidingSync::new(&*sliding_sync.inner.rooms.read().await))?,
9592
)
9693
.await?;
9794

@@ -184,7 +181,6 @@ pub(super) async fn restore_sliding_sync_list(
184181
/// Fields restored during `restore_sliding_sync_state`.
185182
#[derive(Default)]
186183
pub(super) struct RestoredFields {
187-
pub delta_token: Option<String>,
188184
pub to_device_token: Option<String>,
189185
pub pos: Option<String>,
190186
pub rooms: BTreeMap<OwnedRoomId, SlidingSyncRoom>,
@@ -223,20 +219,14 @@ pub(super) async fn restore_sliding_sync_state(
223219
.map(|custom_value| serde_json::from_slice::<FrozenSlidingSync>(&custom_value))
224220
{
225221
// `SlidingSync` has been found and successfully deserialized.
226-
Some(Ok(FrozenSlidingSync {
227-
to_device_since,
228-
delta_token: frozen_delta_token,
229-
rooms: frozen_rooms,
230-
})) => {
222+
Some(Ok(FrozenSlidingSync { to_device_since, rooms: frozen_rooms })) => {
231223
trace!("Successfully read the `SlidingSync` from the cache");
232224
// Only update the to-device token if we failed to read it from the crypto store
233225
// above.
234226
if restored_fields.to_device_token.is_none() {
235227
restored_fields.to_device_token = to_device_since;
236228
}
237229

238-
restored_fields.delta_token = frozen_delta_token;
239-
240230
#[cfg(feature = "e2e-encryption")]
241231
{
242232
if let Some(olm_machine) = &*client.olm_machine().await {
@@ -478,11 +468,9 @@ mod tests {
478468
assert!(state_store.get_custom_value(full_storage_key.as_bytes()).await?.is_none());
479469

480470
// Emulate some data to be cached.
481-
let delta_token = "delta_token".to_owned();
482471
let pos = "pos".to_owned();
483472
{
484473
let mut position_guard = sliding_sync.inner.position.lock().await;
485-
position_guard.delta_token = Some(delta_token.clone());
486474
position_guard.pos = Some(pos.clone());
487475

488476
// Then, we can correctly cache the sliding sync instance.
@@ -496,7 +484,6 @@ mod tests {
496484
state_store.get_custom_value(full_storage_key.as_bytes()).await?,
497485
Some(bytes) => {
498486
let deserialized: FrozenSlidingSync = serde_json::from_slice(&bytes)?;
499-
assert_eq!(deserialized.delta_token, Some(delta_token.clone()));
500487
assert!(deserialized.to_device_since.is_none());
501488
}
502489
);
@@ -509,7 +496,6 @@ mod tests {
509496
.expect("must have restored sliding sync fields");
510497

511498
// After restoring, the delta token and to-device token could be read.
512-
assert_eq!(restored_fields.delta_token.unwrap(), delta_token);
513499
assert_eq!(restored_fields.pos.unwrap(), pos);
514500

515501
// Test the "migration" path: assume a missing to-device token in crypto store,
@@ -531,7 +517,6 @@ mod tests {
531517
full_storage_key.as_bytes(),
532518
serde_json::to_vec(&FrozenSlidingSync {
533519
to_device_since: Some(to_device_token.clone()),
534-
delta_token: Some(delta_token.clone()),
535520
rooms: vec![FrozenSlidingSyncRoom {
536521
room_id: owned_room_id!("!r0:matrix.org"),
537522
prev_batch: Some("t0ken".to_owned()),
@@ -547,7 +532,6 @@ mod tests {
547532

548533
// After restoring, the delta token, the to-device since token, stream
549534
// position and rooms could be read from the state store.
550-
assert_eq!(restored_fields.delta_token.unwrap(), delta_token);
551535
assert_eq!(restored_fields.to_device_token.unwrap(), to_device_token);
552536
assert_eq!(restored_fields.pos.unwrap(), pos);
553537
assert_eq!(restored_fields.rooms.len(), 1);

crates/matrix-sdk/src/sliding_sync/mod.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ impl SlidingSync {
424424
//
425425
// Save the new position markers.
426426
position.pos = pos;
427-
position.delta_token = sliding_sync_response.delta_token.clone();
428427

429428
// Keep this position markers in memory, in case it pops from the server.
430429
let mut past_positions = self.inner.past_positions.write().unwrap();
@@ -448,15 +447,14 @@ impl SlidingSync {
448447
}
449448
}
450449

451-
// Collect the `pos` and `delta_token`.
450+
// Collect the `pos`.
452451
//
453452
// Wait on the `position` mutex to be available. It means no request nor
454453
// response is running. The `position` mutex is released whether the response
455454
// has been fully handled successfully, in this case the `pos` is updated, or
456455
// the response handling has failed, in this case the `pos` hasn't been updated
457456
// and the same `pos` will be used for this new request.
458457
let mut position_guard = self.inner.position.clone().lock_owned().await;
459-
let delta_token = position_guard.delta_token.clone();
460458

461459
let to_device_enabled =
462460
self.inner.sticky.read().unwrap().data().extensions.to_device.enabled == Some(true);
@@ -493,7 +491,6 @@ impl SlidingSync {
493491

494492
let mut request = assign!(v4::Request::new(), {
495493
conn_id: Some(self.inner.id.clone()),
496-
delta_token,
497494
pos,
498495
timeout: Some(self.inner.poll_timeout),
499496
lists: requests_lists,
@@ -874,13 +871,6 @@ pub(super) struct SlidingSyncPositionMarkers {
874871
///
875872
/// Should not be persisted.
876873
pos: Option<String>,
877-
878-
/// Server-provided opaque token that remembers what the last timeline and
879-
/// state events stored by the client were.
880-
///
881-
/// If `None`, the server will send the full information for all the lists
882-
/// present in the request.
883-
delta_token: Option<String>,
884874
}
885875

886876
/// Frozen bits of a Sliding Sync that are stored in the *state* store.
@@ -889,20 +879,14 @@ struct FrozenSlidingSync {
889879
/// Deprecated: prefer storing in the crypto store.
890880
#[serde(skip_serializing_if = "Option::is_none")]
891881
to_device_since: Option<String>,
892-
#[serde(skip_serializing_if = "Option::is_none")]
893-
delta_token: Option<String>,
894882
#[serde(default, skip_serializing_if = "Vec::is_empty")]
895883
rooms: Vec<FrozenSlidingSyncRoom>,
896884
}
897885

898886
impl FrozenSlidingSync {
899-
fn new(
900-
position: &SlidingSyncPositionMarkers,
901-
rooms: &BTreeMap<OwnedRoomId, SlidingSyncRoom>,
902-
) -> Self {
887+
fn new(rooms: &BTreeMap<OwnedRoomId, SlidingSyncRoom>) -> Self {
903888
// The to-device token must be saved in the `FrozenCryptoSlidingSync` now.
904889
Self {
905-
delta_token: position.delta_token.clone(),
906890
to_device_since: None,
907891
rooms: rooms
908892
.iter()
@@ -1200,8 +1184,7 @@ mod tests {
12001184

12011185
// FrozenSlidingSync doesn't contain the to_device_token anymore, as it's saved
12021186
// in the crypto store since PR #2323.
1203-
let position_guard = sliding_sync.inner.position.lock().await;
1204-
let frozen = FrozenSlidingSync::new(&position_guard, &Default::default());
1187+
let frozen = FrozenSlidingSync::new(&*sliding_sync.inner.rooms.read().await);
12051188
assert!(frozen.to_device_since.is_none());
12061189

12071190
Ok(())

0 commit comments

Comments
 (0)