mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-08 16:04:13 -04:00
feat(sliding sync): also empty the list caches when expiring a session
This commit is contained in:
@@ -12,6 +12,8 @@ use tracing::{trace, warn};
|
||||
use super::{FrozenSlidingSyncList, SlidingSync, SlidingSyncPositionMarkers};
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
use crate::sliding_sync::FrozenSlidingSyncPos;
|
||||
#[cfg(doc)]
|
||||
use crate::sliding_sync::SlidingSyncList;
|
||||
use crate::{sliding_sync::SlidingSyncListCachePolicy, Client, Result};
|
||||
|
||||
/// Be careful: as this is used as a storage key; changing it requires migrating
|
||||
@@ -142,7 +144,7 @@ pub(super) async fn restore_sliding_sync_list(
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Fields restored during `restore_sliding_sync_state`.
|
||||
/// Fields restored during [`restore_sliding_sync_state`].
|
||||
#[derive(Default)]
|
||||
pub(super) struct RestoredFields {
|
||||
pub to_device_token: Option<String>,
|
||||
|
||||
@@ -211,7 +211,6 @@ impl SlidingSyncList {
|
||||
}
|
||||
|
||||
/// Set the maximum number of rooms.
|
||||
#[cfg(test)]
|
||||
pub(super) fn set_maximum_number_of_rooms(&self, maximum_number_of_rooms: Option<u32>) {
|
||||
self.inner.maximum_number_of_rooms.set(maximum_number_of_rooms);
|
||||
}
|
||||
|
||||
@@ -725,14 +725,29 @@ impl SlidingSync {
|
||||
pub async fn expire_session(&self) {
|
||||
info!("Session expired; resetting `pos` and sticky parameters");
|
||||
|
||||
{
|
||||
let lists = self.inner.lists.read().await;
|
||||
for list in lists.values() {
|
||||
// Invalidate in-memory data that would be persisted on disk.
|
||||
list.set_maximum_number_of_rooms(None);
|
||||
|
||||
// Invalidate the sticky data for this list.
|
||||
list.invalidate_sticky_data();
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the cached sliding sync state as well.
|
||||
{
|
||||
let mut position = self.inner.position.lock().await;
|
||||
|
||||
// Invalidate in memory.
|
||||
position.pos = None;
|
||||
|
||||
// Propagate to disk.
|
||||
// Note: this propagates both the sliding sync state and the cached lists'
|
||||
// state to disk.
|
||||
if let Err(err) = self.cache_to_storage(&position).await {
|
||||
error!(
|
||||
"couldn't invalidate sliding sync frozen state when expiring session: {err}"
|
||||
);
|
||||
warn!("Failed to invalidate cached sliding sync state: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -743,8 +758,6 @@ impl SlidingSync {
|
||||
// when the session will restart.
|
||||
sticky.data_mut().room_subscriptions.clear();
|
||||
}
|
||||
|
||||
self.inner.lists.read().await.values().for_each(|list| list.invalidate_sticky_data());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user