Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(event cache): enable persistent storage by default 😎 #4308

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions bindings/matrix-sdk-ffi/src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,6 @@ pub struct ClientBuilder {
room_key_recipient_strategy: CollectStrategy,
decryption_trust_requirement: TrustRequirement,
request_config: Option<RequestConfig>,

/// Whether to enable use of the event cache store, for reloading events
/// when building timelines et al.
use_event_cache_persistent_storage: bool,
}

#[matrix_sdk_ffi_macros::export]
Expand Down Expand Up @@ -306,27 +302,9 @@ impl ClientBuilder {
room_key_recipient_strategy: Default::default(),
decryption_trust_requirement: TrustRequirement::Untrusted,
request_config: Default::default(),
use_event_cache_persistent_storage: false,
})
}

/// Whether to use the event cache persistent storage or not.
///
/// This is a temporary feature flag, for testing the event cache's
/// persistent storage. Follow new developments in https://github.com/matrix-org/matrix-rust-sdk/issues/3280.
///
/// This is disabled by default. When disabled, a one-time cleanup is
/// performed when creating the client, and it will clear all the events
/// previously stored in the event cache.
///
/// When enabled, it will attempt to store events in the event cache as
/// they're received, and reuse them when reconstructing timelines.
pub fn use_event_cache_persistent_storage(self: Arc<Self>, value: bool) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.use_event_cache_persistent_storage = value;
Arc::new(builder)
}

pub fn cross_process_store_locks_holder_name(
self: Arc<Self>,
holder_name: String,
Expand Down Expand Up @@ -649,19 +627,6 @@ impl ClientBuilder {

let sdk_client = inner_builder.build().await?;

if builder.use_event_cache_persistent_storage {
// Enable the persistent storage \o/
sdk_client.event_cache().enable_storage()?;
} else {
// Get rid of all the previous events, if any.
let store = sdk_client
.event_cache_store()
.lock()
.await
.map_err(EventCacheError::LockingStorage)?;
store.clear_all_rooms_chunks().await.map_err(EventCacheError::Storage)?;
}

Ok(Arc::new(
Client::new(sdk_client, builder.enable_oidc_refresh_lock, builder.session_delegate)
.await?,
Expand Down
1 change: 0 additions & 1 deletion bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ impl RoomListItem {
let mut timeline_builder = self
.inner
.default_room_timeline_builder()
.await
.map_err(|err| RoomListError::InitializingTimeline { error: err.to_string() })?;

if let Some(event_type_filter) = event_type_filter {
Expand Down
14 changes: 6 additions & 8 deletions crates/matrix-sdk-ui/src/room_list_service/filters/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ pub fn new_filter(filters: Vec<BoxedFilterFn>) -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_one_filter() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

{
let filter = |_: &_| true;
Expand All @@ -54,8 +52,8 @@ mod tests {

#[async_test]
async fn test_two_filters() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

{
let filter1 = |_: &_| true;
Expand Down
30 changes: 14 additions & 16 deletions crates/matrix-sdk-ui/src/room_list_service/filters/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ pub fn new_filter(filters: Vec<BoxedFilterFn>) -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_one_filter_is_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter = |_: &_| true;
let any = new_filter(vec![Box::new(filter)]);
Expand All @@ -45,8 +43,8 @@ mod tests {

#[async_test]
async fn test_one_filter_is_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter = |_: &_| false;
let any = new_filter(vec![Box::new(filter)]);
Expand All @@ -56,8 +54,8 @@ mod tests {

#[async_test]
async fn test_two_filters_with_true_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter1 = |_: &_| true;
let filter2 = |_: &_| true;
Expand All @@ -68,8 +66,8 @@ mod tests {

#[async_test]
async fn test_two_filters_with_true_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter1 = |_: &_| true;
let filter2 = |_: &_| false;
Expand All @@ -80,8 +78,8 @@ mod tests {

#[async_test]
async fn test_two_filters_with_false_true() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter1 = |_: &_| false;
let filter2 = |_: &_| true;
Expand All @@ -92,8 +90,8 @@ mod tests {

#[async_test]
async fn test_two_filters_with_false_false() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let filter1 = |_: &_| false;
let filter2 = |_: &_| false;
Expand Down
18 changes: 8 additions & 10 deletions crates/matrix-sdk-ui/src/room_list_service/filters/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,16 @@ pub fn new_filter(expected_category: RoomCategory) -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_kind_is_group() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = CategoryRoomMatcher { number_of_direct_targets: |_| Some(42) };

Expand All @@ -111,8 +109,8 @@ mod tests {

#[async_test]
async fn test_kind_is_people() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = CategoryRoomMatcher { number_of_direct_targets: |_| Some(1) };

Expand All @@ -133,8 +131,8 @@ mod tests {

#[async_test]
async fn test_room_kind_cannot_be_found() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = CategoryRoomMatcher { number_of_direct_targets: |_| None };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ pub fn new_filter() -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_is_favourite() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = FavouriteRoomMatcher { is_favourite: |_| true };

Expand All @@ -62,8 +60,8 @@ mod tests {

#[async_test]
async fn test_is_not_favourite() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let matcher = FavouriteRoomMatcher { is_favourite: |_| false };

Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk-ui/src/room_list_service/filters/invite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ pub fn new_filter() -> impl Filter {

#[cfg(test)]
mod tests {
use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_base::RoomState;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_all_invite_kind() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

// When a room has been left, it doesn't match.
let matcher = InviteRoomMatcher { state: |_| RoomState::Left };
Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk-ui/src/room_list_service/filters/joined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,17 @@ pub fn new_filter() -> impl Filter {

#[cfg(test)]
mod tests {
use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_base::RoomState;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_all_joined_kind() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

// When a room has been left, it doesn't match.
let matcher = JoinedRoomMatcher { state: |_| RoomState::Left };
Expand Down
16 changes: 2 additions & 14 deletions crates/matrix-sdk-ui/src/room_list_service/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ mod normalized_match_room_name;
mod not;
mod unread;

#[cfg(test)]
use std::sync::Arc;

pub use all::new_filter as new_filter_all;
pub use any::new_filter as new_filter_any;
pub use category::{new_filter as new_filter_category, RoomCategory};
Expand All @@ -75,7 +72,7 @@ pub use fuzzy_match_room_name::new_filter as new_filter_fuzzy_match_room_name;
pub use invite::new_filter as new_filter_invite;
pub use joined::new_filter as new_filter_joined;
#[cfg(test)]
use matrix_sdk::{test_utils::logged_in_client_with_server, Client, SlidingSync};
use matrix_sdk::Client;
#[cfg(test)]
use matrix_sdk_test::{JoinedRoomBuilder, SyncResponseBuilder};
pub use non_left::new_filter as new_filter_non_left;
Expand Down Expand Up @@ -116,7 +113,6 @@ pub(super) async fn new_rooms<const N: usize>(
room_ids: [&RoomId; N],
client: &Client,
server: &MockServer,
sliding_sync: &Arc<SlidingSync>,
) -> [Room; N] {
let mut response_builder = SyncResponseBuilder::default();

Expand All @@ -135,15 +131,7 @@ pub(super) async fn new_rooms<const N: usize>(

let _response = client.sync_once(Default::default()).await.unwrap();

room_ids.map(|room_id| Room::new(client.get_room(room_id).unwrap(), sliding_sync))
}

#[cfg(test)]
pub(super) async fn client_and_server_prelude() -> (Client, MockServer, Arc<SlidingSync>) {
let (client, server) = logged_in_client_with_server().await;
let sliding_sync = Arc::new(client.sliding_sync("foo").unwrap().build().await.unwrap());

(client, server, sliding_sync)
room_ids.map(|room_id| Room::new(client.get_room(room_id).unwrap()))
}

#[cfg(test)]
Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk-ui/src/room_list_service/filters/non_left.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,17 @@ pub fn new_filter() -> impl Filter {

#[cfg(test)]
mod tests {
use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_base::RoomState;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_all_non_left_kind_of_room_list_entry() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

// When a room has been left, it doesn't match.
let matcher = NonLeftRoomMatcher { state: |_| RoomState::Left };
Expand Down
10 changes: 4 additions & 6 deletions crates/matrix-sdk-ui/src/room_list_service/filters/none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ pub fn new_filter() -> impl Filter {
mod tests {
use std::ops::Not;

use matrix_sdk::test_utils::logged_in_client_with_server;
use matrix_sdk_test::async_test;
use ruma::room_id;

use super::{
super::{client_and_server_prelude, new_rooms},
*,
};
use super::{super::new_rooms, *};

#[async_test]
async fn test_all_kind_of_room_list_entry() {
let (client, server, sliding_sync) = client_and_server_prelude().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server, &sliding_sync).await;
let (client, server) = logged_in_client_with_server().await;
let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await;

let none = new_filter();

Expand Down
Loading
Loading