Skip to content

Commit 0ec90c2

Browse files
committed
base: move the initial filling of the display name cache into the sync methods
It's not perfect, but it's honest work.
1 parent c72384f commit 0ec90c2

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

crates/matrix-sdk-base/src/client.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,13 @@ impl BaseClient {
10711071
self.apply_changes(&changes, false);
10721072
}
10731073

1074+
// Now that all the rooms information have been saved, update the display name
1075+
// cache (which relies on information stored in the database). This will
1076+
// live in memory, until the next sync which will saves the room info to
1077+
// disk; we do this to avoid saving that would be redundant with the
1078+
// above. Oh well.
1079+
new_rooms.update_in_memory_caches(&self.store).await;
1080+
10741081
info!("Processed a sync response in {:?}", now.elapsed());
10751082

10761083
let response = SyncResponse {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ impl BaseClient {
295295
self.apply_changes(&changes, false);
296296
trace!("applied changes");
297297

298+
// Now that all the rooms information have been saved, update the display name
299+
// cache (which relies on information stored in the database). This will
300+
// live in memory, until the next sync which will saves the room info to
301+
// disk; we do this to avoid saving that would be redundant with the
302+
// above. Oh well.
303+
new_rooms.update_in_memory_caches(&self.store).await;
304+
298305
Ok(SyncResponse {
299306
rooms: new_rooms,
300307
notifications,

crates/matrix-sdk-base/src/sync.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use serde::{Deserialize, Serialize};
3535
use crate::{
3636
debug::{DebugInvitedRoom, DebugListOfRawEvents, DebugListOfRawEventsNoId},
3737
deserialized_responses::{AmbiguityChange, RawAnySyncOrStrippedTimelineEvent},
38+
store::Store,
3839
};
3940

4041
/// Generalized representation of a `/sync` response.
@@ -78,6 +79,23 @@ pub struct RoomUpdates {
7879
pub invite: BTreeMap<OwnedRoomId, InvitedRoomUpdate>,
7980
}
8081

82+
impl RoomUpdates {
83+
/// Update the caches for the rooms that received updates.
84+
///
85+
/// This will only fill the in-memory caches, not save the info on disk.
86+
pub(crate) async fn update_in_memory_caches(&self, store: &Store) {
87+
for room in self
88+
.leave
89+
.keys()
90+
.chain(self.join.keys())
91+
.chain(self.invite.keys())
92+
.filter_map(|room_id| store.get_room(room_id))
93+
{
94+
let _ = room.compute_display_name().await;
95+
}
96+
}
97+
}
98+
8199
#[cfg(not(tarpaulin_include))]
82100
impl fmt::Debug for RoomUpdates {
83101
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/matrix-sdk/src/sync.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,6 @@ impl Client {
154154
) -> Result<()> {
155155
let BaseSyncResponse { rooms, presence, account_data, to_device, notifications } = response;
156156

157-
{
158-
// Recompute the computed display name for all the rooms which had an update.
159-
for room in rooms
160-
.leave
161-
.keys()
162-
.chain(rooms.join.keys())
163-
.chain(rooms.invite.keys())
164-
.filter_map(|room_id| self.get_room(room_id))
165-
{
166-
let _ = room.compute_display_name().await;
167-
}
168-
}
169-
170157
let now = Instant::now();
171158
self.handle_sync_events(HandlerKind::GlobalAccountData, None, account_data).await?;
172159
self.handle_sync_events(HandlerKind::Presence, None, presence).await?;

0 commit comments

Comments
 (0)