From 67ff82ef40ce8190969a119d29ae008b668fbed7 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 19 Nov 2024 10:24:29 +0100 Subject: [PATCH] feat(base): Add `EventCacheStore::handle_linked_chunk_updates`. This patch adds the `handle_linked_chunk_updates` method on the `EventCacheStore` trait. Part of https://github.com/matrix-org/matrix-rust-sdk/issues/3280. --- .../src/event_cache/store/memory_store.rs | 15 +++++++++++++-- .../src/event_cache/store/traits.rs | 19 +++++++++++++++++-- .../matrix-sdk-common/src/linked_chunk/mod.rs | 4 ++-- .../src/event_cache_store.rs | 7 +++++++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/crates/matrix-sdk-base/src/event_cache/store/memory_store.rs b/crates/matrix-sdk-base/src/event_cache/store/memory_store.rs index 1b5debbcce..3b3326e73b 100644 --- a/crates/matrix-sdk-base/src/event_cache/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/event_cache/store/memory_store.rs @@ -16,12 +16,16 @@ use std::{collections::HashMap, num::NonZeroUsize, sync::RwLock as StdRwLock, ti use async_trait::async_trait; use matrix_sdk_common::{ - ring_buffer::RingBuffer, store_locks::memory_store_helper::try_take_leased_lock, + linked_chunk::Update, ring_buffer::RingBuffer, + store_locks::memory_store_helper::try_take_leased_lock, }; use ruma::{MxcUri, OwnedMxcUri}; use super::{EventCacheStore, EventCacheStoreError, Result}; -use crate::media::{MediaRequestParameters, UniqueKey as _}; +use crate::{ + event_cache::{Event, Gap}, + media::{MediaRequestParameters, UniqueKey as _}, +}; /// In-memory, non-persistent implementation of the `EventCacheStore`. /// @@ -66,6 +70,13 @@ impl EventCacheStore for MemoryStore { Ok(try_take_leased_lock(&self.leases, lease_duration_ms, key, holder)) } + async fn handle_linked_chunk_updates( + &self, + updates: &[Update], + ) -> Result<(), Self::Error> { + todo!() + } + async fn add_media_content( &self, request: &MediaRequestParameters, diff --git a/crates/matrix-sdk-base/src/event_cache/store/traits.rs b/crates/matrix-sdk-base/src/event_cache/store/traits.rs index e52ad8b8b2..44376a24f3 100644 --- a/crates/matrix-sdk-base/src/event_cache/store/traits.rs +++ b/crates/matrix-sdk-base/src/event_cache/store/traits.rs @@ -15,11 +15,14 @@ use std::{fmt, sync::Arc}; use async_trait::async_trait; -use matrix_sdk_common::AsyncTraitDeps; +use matrix_sdk_common::{linked_chunk::Update, AsyncTraitDeps}; use ruma::MxcUri; use super::EventCacheStoreError; -use crate::media::MediaRequestParameters; +use crate::{ + event_cache::{Event, Gap}, + media::MediaRequestParameters, +}; /// An abstract trait that can be used to implement different store backends /// for the event cache of the SDK. @@ -37,6 +40,11 @@ pub trait EventCacheStore: AsyncTraitDeps { holder: &str, ) -> Result; + async fn handle_linked_chunk_updates( + &self, + updates: &[Update], + ) -> Result<(), Self::Error>; + /// Add a media file's content in the media store. /// /// # Arguments @@ -131,6 +139,13 @@ impl EventCacheStore for EraseEventCacheStoreError { self.0.try_take_leased_lock(lease_duration_ms, key, holder).await.map_err(Into::into) } + async fn handle_linked_chunk_updates( + &self, + updates: &[Update], + ) -> Result<(), Self::Error> { + self.0.handle_linked_chunk_updates(updates).await.map_err(Into::into) + } + async fn add_media_content( &self, request: &MediaRequestParameters, diff --git a/crates/matrix-sdk-common/src/linked_chunk/mod.rs b/crates/matrix-sdk-common/src/linked_chunk/mod.rs index b2894f8646..eeba29be30 100644 --- a/crates/matrix-sdk-common/src/linked_chunk/mod.rs +++ b/crates/matrix-sdk-common/src/linked_chunk/mod.rs @@ -103,8 +103,8 @@ use std::{ sync::atomic::{AtomicU64, Ordering}, }; -use as_vector::*; -use updates::*; +pub use as_vector::*; +pub use updates::*; /// Errors of [`LinkedChunk`]. #[derive(thiserror::Error, Debug)] diff --git a/crates/matrix-sdk-sqlite/src/event_cache_store.rs b/crates/matrix-sdk-sqlite/src/event_cache_store.rs index c5a21fb0a6..7afac4f053 100644 --- a/crates/matrix-sdk-sqlite/src/event_cache_store.rs +++ b/crates/matrix-sdk-sqlite/src/event_cache_store.rs @@ -182,6 +182,13 @@ impl EventCacheStore for SqliteEventCacheStore { Ok(num_touched == 1) } + async fn handle_linked_chunk_updates( + &self, + updates: &[Update], + ) -> Result<(), Self::Error> { + todo!() + } + async fn add_media_content( &self, request: &MediaRequestParameters,