From 79f408b511f4f1360fd698a166cdb5b2423c879a Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 28 Sep 2023 16:23:29 +0200 Subject: [PATCH] feat: automatically reload the tracked users when getting the cache --- crates/matrix-sdk-crypto/src/store/mod.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 1c71b49b2..2b2678b96 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -567,7 +567,13 @@ impl Store { // - try to take the lock, // - if acquired, look if another process touched the underlying storage, // - if yes, reload everything; if no, return current cache - Ok(StoreCacheGuard { cache: &self.inner.cache }) + + let cache = StoreCacheGuard { cache: &self.inner.cache }; + + // Make sure tracked users are always up to date. + self.ensure_sync_tracked_users(&cache).await?; + + Ok(cache) } #[cfg(test)] @@ -904,7 +910,6 @@ impl Store { users: impl Iterator, ) -> Result<()> { let cache = self.cache().await?; - self.ensure_sync_tracked_users(&cache).await?; let mut store_updates = Vec::new(); let mut key_query_lock = self.inner.users_for_key_query.lock().await; @@ -931,7 +936,6 @@ impl Store { users: impl Iterator, ) -> Result<()> { let cache = self.cache().await?; - self.ensure_sync_tracked_users(&cache).await?; let mut store_updates: Vec<(&UserId, bool)> = Vec::new(); let mut key_query_lock = self.inner.users_for_key_query.lock().await; @@ -1029,8 +1033,8 @@ impl Store { pub(crate) async fn users_for_key_query( &self, ) -> Result<(HashSet, SequenceNumber)> { - let cache = self.cache().await?; - self.ensure_sync_tracked_users(&cache).await?; + // Make sure the tracked users set is up to date. + let _cache = self.cache().await?; Ok(self.inner.users_for_key_query.lock().await.users_for_key_query()) } @@ -1074,7 +1078,6 @@ impl Store { /// See the docs for [`crate::OlmMachine::tracked_users()`]. pub(crate) async fn tracked_users(&self) -> Result> { let cache = self.cache().await?; - self.ensure_sync_tracked_users(&cache).await?; Ok(cache.tracked_users.iter().map(|u| u.clone()).collect()) }