From 5fe1c3e65d11eb36234db11f2c8a7947f033b9ed Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 19 Aug 2025 17:24:48 +0200 Subject: [PATCH] fixup! feat(event cache): use the event cache store lock as little as we must --- crates/matrix-sdk/src/event_cache/pagination.rs | 2 +- crates/matrix-sdk/src/event_cache/room/mod.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk/src/event_cache/pagination.rs b/crates/matrix-sdk/src/event_cache/pagination.rs index f1ef14210..e928f4b65 100644 --- a/crates/matrix-sdk/src/event_cache/pagination.rs +++ b/crates/matrix-sdk/src/event_cache/pagination.rs @@ -180,7 +180,7 @@ impl RoomPagination { loop { let mut state_guard = self.inner.state.write().await; - match state_guard.load_more_events_backwards().await? { + match state_guard.load_more_events_backwards(&self.inner.store).await? { LoadMoreEventsBackwardsOutcome::WaitForInitialPrevToken => { const DEFAULT_WAIT_FOR_TOKEN_DURATION: Duration = Duration::from_secs(3); diff --git a/crates/matrix-sdk/src/event_cache/room/mod.rs b/crates/matrix-sdk/src/event_cache/room/mod.rs index 7ca188870..02cf0277e 100644 --- a/crates/matrix-sdk/src/event_cache/room/mod.rs +++ b/crates/matrix-sdk/src/event_cache/room/mod.rs @@ -976,6 +976,7 @@ mod private { /// Load more events backwards if the last chunk is **not** a gap. pub(in super::super) async fn load_more_events_backwards( &mut self, + store_lock: &EventCacheStoreLock, ) -> Result { // If any in-memory chunk is a gap, don't load more events, and let the caller // resolve the gap. @@ -992,7 +993,7 @@ mod private { .expect("a linked chunk is never empty") .identifier(); - let store = self.store.lock().await?; + let store = store_lock.lock().await?; // The first chunk is not a gap, we can load its previous chunk. let linked_chunk_id = LinkedChunkId::Room(&self.room); @@ -2988,7 +2989,7 @@ mod timed_tests { // But if I manually reload more of the chunk, the gap will be present. assert_matches!( - state.load_more_events_backwards().await.unwrap(), + state.load_more_events_backwards(&room_event_cache.inner.store).await.unwrap(), LoadMoreEventsBackwardsOutcome::Gap { .. } );