mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-21 07:37:47 -04:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -463,7 +463,7 @@ impl PinnedEventCache {
|
||||
async fn reload_pinned_events(room: Room) -> Result<Option<Vec<Event>>> {
|
||||
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)
|
||||
};
|
||||
|
||||
|
||||
@@ -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<Target = EventCacheConfig> + '_ {
|
||||
self.inner.config.read().await
|
||||
pub fn config(&self) -> impl Deref<Target = EventCacheConfig> + '_ {
|
||||
self.inner.config.read().unwrap()
|
||||
}
|
||||
|
||||
/// Get a writable handle to the global configuration of the [`EventCache`].
|
||||
pub async fn config_mut(&self) -> impl DerefMut<Target = EventCacheConfig> + '_ {
|
||||
self.inner.config.write().await
|
||||
pub fn config_mut(&self) -> impl DerefMut<Target = EventCacheConfig> + '_ {
|
||||
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<EventCacheConfig>,
|
||||
config: StdRwLock<EventCacheConfig>,
|
||||
|
||||
/// Reference to the underlying store.
|
||||
store: EventCacheStoreLock,
|
||||
|
||||
Reference in New Issue
Block a user