Skip to content

Commit c7e1bdb

Browse files
committed
fix(sdk): Reload all the “inner states” of a RoomEventCache at once.
`RoomEventCache` holds the states for the room cache, the thread caches, and the pinned-events cache. When the cross-process lock is dirty, it has to reload all these caches. Ideally, we must move all the states in a single struct, behind the cross-process lock, because right now, when the lock is dirty, only a single room is reloaded, not all the rooms. This is a temporary fix.
1 parent 2d61792 commit c7e1bdb

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

crates/matrix-sdk/src/event_cache/caches/pinned_events/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ use tracing::{debug, instrument, trace, warn};
3636
use super::super::redecryptor::ResolvedUtd;
3737
use super::{
3838
super::{EventCacheError, EventsOrigin, Result, persistence::send_updates_to_store},
39+
TimelineVectorDiffs,
3940
event_linked_chunk::EventLinkedChunk,
4041
lock,
42+
lock::Reload as _,
4143
room::RoomEventCacheLinkedChunkUpdate,
4244
};
43-
use crate::{
44-
Room, client::WeakClient, config::RequestConfig, event_cache::TimelineVectorDiffs,
45-
room::WeakRoom,
46-
};
45+
use crate::{Room, client::WeakClient, config::RequestConfig, room::WeakRoom};
4746

4847
pub(in super::super) struct PinnedEventCacheState {
4948
/// The ID of the room owning this list of pinned events.
@@ -542,4 +541,12 @@ impl PinnedEventCache {
542541

543542
Ok(Some(loaded_events))
544543
}
544+
545+
/// Force to reload the pinned events.
546+
//
547+
// TODO(@hywan): Temporary fix. All the states must be in a single struct behind
548+
// the cross-process lock instead of being dispatched in each cache.
549+
pub(super) async fn reload(&self) -> Result<()> {
550+
self.state.write().await?.reload().await
551+
}
545552
}

crates/matrix-sdk/src/event_cache/caches/room/state.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,16 @@ impl<'a> lock::Reload for RoomEventCacheStateLockWriteGuard<'a> {
413413
async fn reload(&mut self) -> Result<(), EventCacheError> {
414414
self.shrink_to_last_chunk().await?;
415415

416+
// Reload the threads.
417+
for (_thread_id, thread_event_cache) in &mut self.threads {
418+
thread_event_cache.reload().await?;
419+
}
420+
421+
// Reload the pinned-events.
422+
if let Some(pinned_event_cache) = self.pinned_event_cache.get_mut() {
423+
pinned_event_cache.reload().await?;
424+
}
425+
416426
let diffs = self.state.room_linked_chunk.updates_as_vector_diffs();
417427

418428
// Notify observers about the update.

crates/matrix-sdk/src/event_cache/caches/thread/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use self::{pagination::ThreadPagination, updates::ThreadEventCacheUpdateSender};
3333
use super::{
3434
super::Result,
3535
EventsOrigin, TimelineVectorDiffs,
36+
lock::Reload as _,
3637
room::{RoomEventCacheGenericUpdate, RoomEventCacheLinkedChunkUpdate},
3738
};
3839
use crate::room::WeakRoom;
@@ -229,6 +230,14 @@ impl ThreadEventCache {
229230
.and_then(|(_position, event)| event.event_id()))
230231
}
231232

233+
/// Force to reload the thread.
234+
//
235+
// TODO(@hywan): Temporary fix. All the states must be in a single struct behind
236+
// the cross-process lock instead of being dispatched in each cache.
237+
pub(super) async fn reload(&self) -> Result<()> {
238+
self.inner.state.write().await?.reload().await
239+
}
240+
232241
/// Find a single event in this thread.
233242
///
234243
/// It starts by looking into loaded events in `EventLinkedChunk` before

0 commit comments

Comments
 (0)