mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-08 07:56:55 -04:00
base: move the initial filling of the display name cache into the sync methods
It's not perfect, but it's honest work.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<OwnedRoomId, InvitedRoomUpdate>,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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?;
|
||||
|
||||
Reference in New Issue
Block a user