diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 33f5d215f03..26adfb424b5 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -1071,6 +1071,13 @@ impl BaseClient { self.apply_changes(&changes, false); } + // Now that all the rooms information have been saved, update the display name + // cache (which relies on information stored in the database). This will + // live in memory, until the next sync which will saves the room info to + // disk; we do this to avoid saving that would be redundant with the + // above. Oh well. + new_rooms.update_in_memory_caches(&self.store).await; + info!("Processed a sync response in {:?}", now.elapsed()); let response = SyncResponse { diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 6263a9459c2..939d3cbddb3 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -295,6 +295,13 @@ impl BaseClient { self.apply_changes(&changes, false); trace!("applied changes"); + // Now that all the rooms information have been saved, update the display name + // cache (which relies on information stored in the database). This will + // live in memory, until the next sync which will saves the room info to + // disk; we do this to avoid saving that would be redundant with the + // above. Oh well. + new_rooms.update_in_memory_caches(&self.store).await; + Ok(SyncResponse { rooms: new_rooms, notifications, diff --git a/crates/matrix-sdk-base/src/sync.rs b/crates/matrix-sdk-base/src/sync.rs index 23f1bff59a4..50cc6210b19 100644 --- a/crates/matrix-sdk-base/src/sync.rs +++ b/crates/matrix-sdk-base/src/sync.rs @@ -35,6 +35,7 @@ use serde::{Deserialize, Serialize}; use crate::{ debug::{DebugInvitedRoom, DebugListOfRawEvents, DebugListOfRawEventsNoId}, deserialized_responses::{AmbiguityChange, RawAnySyncOrStrippedTimelineEvent}, + store::Store, }; /// Generalized representation of a `/sync` response. @@ -78,6 +79,23 @@ pub struct RoomUpdates { pub invite: BTreeMap, } +impl RoomUpdates { + /// Update the caches for the rooms that received updates. + /// + /// This will only fill the in-memory caches, not save the info on disk. + pub(crate) async fn update_in_memory_caches(&self, store: &Store) { + for room in self + .leave + .keys() + .chain(self.join.keys()) + .chain(self.invite.keys()) + .filter_map(|room_id| store.get_room(room_id)) + { + let _ = room.compute_display_name().await; + } + } +} + #[cfg(not(tarpaulin_include))] impl fmt::Debug for RoomUpdates { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/matrix-sdk/src/sync.rs b/crates/matrix-sdk/src/sync.rs index 8c3ecec3473..1aa3792c2c3 100644 --- a/crates/matrix-sdk/src/sync.rs +++ b/crates/matrix-sdk/src/sync.rs @@ -154,19 +154,6 @@ impl Client { ) -> Result<()> { let BaseSyncResponse { rooms, presence, account_data, to_device, notifications } = response; - { - // Recompute the computed display name for all the rooms which had an update. - for room in rooms - .leave - .keys() - .chain(rooms.join.keys()) - .chain(rooms.invite.keys()) - .filter_map(|room_id| self.get_room(room_id)) - { - let _ = room.compute_display_name().await; - } - } - let now = Instant::now(); self.handle_sync_events(HandlerKind::GlobalAccountData, None, account_data).await?; self.handle_sync_events(HandlerKind::Presence, None, presence).await?;