From bf9ffd7d09dca14e92af3529c78acd24b3c75fa3 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 23 Mar 2026 15:21:21 +0100 Subject: [PATCH] refactor(event cache): make `EventCache::config/config_mut` sync by using a sync lock There wasn't good reason to use an async lock, as this lock is always super short-lived, it can be sync, which avoids complications in the subsequent commit when calling sync init code. --- bindings/matrix-sdk-ffi/src/client.rs | 4 ++-- .../tests/integration/timeline/pinned_event.rs | 4 ++-- .../src/event_cache/caches/pinned_events/mod.rs | 2 +- crates/matrix-sdk/src/event_cache/mod.rs | 14 +++++++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index caf82cfe5..b3e7814da 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -2110,8 +2110,8 @@ impl Client { /// /// This is an experimental feature, and might cause performance issues on /// large accounts. Use with caution. - pub async fn enable_automatic_backpagination(&self) { - self.inner.event_cache().config_mut().await.experimental_auto_backpagination = true; + pub fn enable_automatic_backpagination(&self) { + self.inner.event_cache().config_mut().experimental_auto_backpagination = true; } } diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs b/crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs index b93eee4ed..5512641f9 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/pinned_event.rs @@ -389,7 +389,7 @@ async fn test_max_events_to_load_is_honored() { let client = server.client_builder().build().await; let room_id = room_id!("!test:localhost"); - client.event_cache().config_mut().await.max_pinned_events_to_load = 1; + client.event_cache().config_mut().max_pinned_events_to_load = 1; let f = EventFactory::new().room(room_id).sender(*BOB); let pinned_event = f @@ -869,7 +869,7 @@ async fn test_ensure_max_concurrency_is_observed() { let max_concurrent_requests = 10; // Define the max concurrent requests allowed for the event cache. - client.event_cache().config_mut().await.max_pinned_events_concurrent_requests = + client.event_cache().config_mut().max_pinned_events_concurrent_requests = max_concurrent_requests; let f = EventFactory::new().room(&room_id).sender(user_id!("@example:localhost")); diff --git a/crates/matrix-sdk/src/event_cache/caches/pinned_events/mod.rs b/crates/matrix-sdk/src/event_cache/caches/pinned_events/mod.rs index 0af9f9c35..819aba644 100644 --- a/crates/matrix-sdk/src/event_cache/caches/pinned_events/mod.rs +++ b/crates/matrix-sdk/src/event_cache/caches/pinned_events/mod.rs @@ -463,7 +463,7 @@ impl PinnedEventCache { async fn reload_pinned_events(room: Room) -> Result>> { let (max_events_to_load, max_concurrent_requests) = { let client = room.client(); - let config = client.event_cache().config().await; + let config = client.event_cache().config(); (config.max_pinned_events_to_load, config.max_pinned_events_concurrent_requests) }; diff --git a/crates/matrix-sdk/src/event_cache/mod.rs b/crates/matrix-sdk/src/event_cache/mod.rs index cb9a915d2..a0b2595d8 100644 --- a/crates/matrix-sdk/src/event_cache/mod.rs +++ b/crates/matrix-sdk/src/event_cache/mod.rs @@ -31,7 +31,7 @@ use std::{ collections::HashMap, fmt, ops::{Deref, DerefMut}, - sync::{Arc, OnceLock}, + sync::{Arc, OnceLock, RwLock as StdRwLock}, }; use futures_util::future::try_join_all; @@ -228,7 +228,7 @@ impl EventCache { Self { inner: Arc::new(EventCacheInner { client: weak_client, - config: RwLock::new(EventCacheConfig::default()), + config: StdRwLock::new(EventCacheConfig::default()), store: event_cache_store, multiple_room_updates_lock: Default::default(), by_room: Default::default(), @@ -249,13 +249,13 @@ impl EventCache { /// Get a read-only handle to the global configuration of the /// [`EventCache`]. - pub async fn config(&self) -> impl Deref + '_ { - self.inner.config.read().await + pub fn config(&self) -> impl Deref + '_ { + self.inner.config.read().unwrap() } /// Get a writable handle to the global configuration of the [`EventCache`]. - pub async fn config_mut(&self) -> impl DerefMut + '_ { - self.inner.config.write().await + pub fn config_mut(&self) -> impl DerefMut + '_ { + self.inner.config.write().unwrap() } /// Subscribes to updates that a thread subscription has been sent. @@ -413,7 +413,7 @@ struct EventCacheInner { client: WeakClient, /// Global configuration for the event cache. - config: RwLock, + config: StdRwLock, /// Reference to the underlying store. store: EventCacheStoreLock,