Skip to content

Commit e5ca44b

Browse files
committed
feat(base): Add EventCacheStore::handle_linked_chunk_updates.
This patch adds the `handle_linked_chunk_updates` method on the `EventCacheStore` trait. Part of #3280.
1 parent 1f563c9 commit e5ca44b

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

crates/matrix-sdk-base/src/event_cache/store/memory_store.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ use std::{collections::HashMap, num::NonZeroUsize, sync::RwLock as StdRwLock, ti
1616

1717
use async_trait::async_trait;
1818
use matrix_sdk_common::{
19-
ring_buffer::RingBuffer, store_locks::memory_store_helper::try_take_leased_lock,
19+
linked_chunk::Update, ring_buffer::RingBuffer,
20+
store_locks::memory_store_helper::try_take_leased_lock,
2021
};
2122
use ruma::{MxcUri, OwnedMxcUri};
2223

2324
use super::{EventCacheStore, EventCacheStoreError, Result};
24-
use crate::media::{MediaRequestParameters, UniqueKey as _};
25+
use crate::{
26+
event_cache::{Event, Gap},
27+
media::{MediaRequestParameters, UniqueKey as _},
28+
};
2529

2630
/// In-memory, non-persistent implementation of the `EventCacheStore`.
2731
///
@@ -66,6 +70,13 @@ impl EventCacheStore for MemoryStore {
6670
Ok(try_take_leased_lock(&self.leases, lease_duration_ms, key, holder))
6771
}
6872

73+
async fn handle_linked_chunk_updates(
74+
&self,
75+
_updates: &[Update<Event, Gap>],
76+
) -> Result<(), Self::Error> {
77+
todo!()
78+
}
79+
6980
async fn add_media_content(
7081
&self,
7182
request: &MediaRequestParameters,

crates/matrix-sdk-base/src/event_cache/store/traits.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
use std::{fmt, sync::Arc};
1616

1717
use async_trait::async_trait;
18-
use matrix_sdk_common::AsyncTraitDeps;
18+
use matrix_sdk_common::{linked_chunk::Update, AsyncTraitDeps};
1919
use ruma::MxcUri;
2020

2121
use super::EventCacheStoreError;
22-
use crate::media::MediaRequestParameters;
22+
use crate::{
23+
event_cache::{Event, Gap},
24+
media::MediaRequestParameters,
25+
};
2326

2427
/// An abstract trait that can be used to implement different store backends
2528
/// for the event cache of the SDK.
@@ -37,6 +40,14 @@ pub trait EventCacheStore: AsyncTraitDeps {
3740
holder: &str,
3841
) -> Result<bool, Self::Error>;
3942

43+
/// An [`Update`] reflects an operation that has happened inside a linked
44+
/// chunk. The linked chunk is used by the event cache to store the events
45+
/// in-memory. This method aims at forwarding this update inside this store.
46+
async fn handle_linked_chunk_updates(
47+
&self,
48+
updates: &[Update<Event, Gap>],
49+
) -> Result<(), Self::Error>;
50+
4051
/// Add a media file's content in the media store.
4152
///
4253
/// # Arguments
@@ -131,6 +142,13 @@ impl<T: EventCacheStore> EventCacheStore for EraseEventCacheStoreError<T> {
131142
self.0.try_take_leased_lock(lease_duration_ms, key, holder).await.map_err(Into::into)
132143
}
133144

145+
async fn handle_linked_chunk_updates(
146+
&self,
147+
updates: &[Update<Event, Gap>],
148+
) -> Result<(), Self::Error> {
149+
self.0.handle_linked_chunk_updates(updates).await.map_err(Into::into)
150+
}
151+
134152
async fn add_media_content(
135153
&self,
136154
request: &MediaRequestParameters,

crates/matrix-sdk-common/src/linked_chunk/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ use std::{
103103
sync::atomic::{AtomicU64, Ordering},
104104
};
105105

106-
use as_vector::*;
107-
use updates::*;
106+
pub use as_vector::*;
107+
pub use updates::*;
108108

109109
/// Errors of [`LinkedChunk`].
110110
#[derive(thiserror::Error, Debug)]

crates/matrix-sdk-common/src/linked_chunk/updates.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ use super::{ChunkIdentifier, Position};
2929
///
3030
/// These updates are useful to store a `LinkedChunk` in another form of
3131
/// storage, like a database or something similar.
32+
///
33+
/// [`LinkedChunk`]: super::LinkedChunk
34+
/// [`LinkedChunk::updates`]: super::LinkedChunk::updates
3235
#[derive(Debug, Clone, PartialEq)]
3336
pub enum Update<Item, Gap> {
3437
/// A new chunk of kind Items has been created.
@@ -101,6 +104,8 @@ pub enum Update<Item, Gap> {
101104
/// A collection of [`Update`]s that can be observed.
102105
///
103106
/// Get a value for this type with [`LinkedChunk::updates`].
107+
///
108+
/// [`LinkedChunk::updates`]: super::LinkedChunk::updates
104109
#[derive(Debug)]
105110
pub struct ObservableUpdates<Item, Gap> {
106111
pub(super) inner: Arc<RwLock<UpdatesInner<Item, Gap>>>,

crates/matrix-sdk-sqlite/src/event_cache_store.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::{borrow::Cow, fmt, path::Path, sync::Arc};
33
use async_trait::async_trait;
44
use deadpool_sqlite::{Object as SqliteAsyncConn, Pool as SqlitePool, Runtime};
55
use matrix_sdk_base::{
6-
event_cache::store::EventCacheStore,
6+
event_cache::{store::EventCacheStore, Event, Gap},
7+
linked_chunk::Update,
78
media::{MediaRequestParameters, UniqueKey},
89
};
910
use matrix_sdk_store_encryption::StoreCipher;
@@ -182,6 +183,13 @@ impl EventCacheStore for SqliteEventCacheStore {
182183
Ok(num_touched == 1)
183184
}
184185

186+
async fn handle_linked_chunk_updates(
187+
&self,
188+
_updates: &[Update<Event, Gap>],
189+
) -> Result<(), Self::Error> {
190+
todo!()
191+
}
192+
185193
async fn add_media_content(
186194
&self,
187195
request: &MediaRequestParameters,

0 commit comments

Comments
 (0)