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:
Benjamin Bouvier
2024-06-10 16:32:17 +02:00
parent c72384f7d4
commit 0ec90c23da
4 changed files with 32 additions and 13 deletions

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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?;