mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-06 23:15:08 -04:00
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.
This commit is contained in:
@@ -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<Event, Gap>],
|
||||
) -> Result<(), Self::Error> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn add_media_content(
|
||||
&self,
|
||||
request: &MediaRequestParameters,
|
||||
|
||||
@@ -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,14 @@ pub trait EventCacheStore: AsyncTraitDeps {
|
||||
holder: &str,
|
||||
) -> Result<bool, Self::Error>;
|
||||
|
||||
/// An [`Update`] reflects an operation that has happened inside a linked
|
||||
/// chunk. The linked chunk is used by the event cache to store the events
|
||||
/// in-memory. This method aims at forwarding this update inside this store.
|
||||
async fn handle_linked_chunk_updates(
|
||||
&self,
|
||||
updates: &[Update<Event, Gap>],
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Add a media file's content in the media store.
|
||||
///
|
||||
/// # Arguments
|
||||
@@ -131,6 +142,13 @@ impl<T: EventCacheStore> EventCacheStore for EraseEventCacheStoreError<T> {
|
||||
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<Event, Gap>],
|
||||
) -> Result<(), Self::Error> {
|
||||
self.0.handle_linked_chunk_updates(updates).await.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn add_media_content(
|
||||
&self,
|
||||
request: &MediaRequestParameters,
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -29,6 +29,9 @@ use super::{ChunkIdentifier, Position};
|
||||
///
|
||||
/// These updates are useful to store a `LinkedChunk` in another form of
|
||||
/// storage, like a database or something similar.
|
||||
///
|
||||
/// [`LinkedChunk`]: super::LinkedChunk
|
||||
/// [`LinkedChunk::updates`]: super::LinkedChunk::updates
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Update<Item, Gap> {
|
||||
/// A new chunk of kind Items has been created.
|
||||
@@ -101,6 +104,8 @@ pub enum Update<Item, Gap> {
|
||||
/// A collection of [`Update`]s that can be observed.
|
||||
///
|
||||
/// Get a value for this type with [`LinkedChunk::updates`].
|
||||
///
|
||||
/// [`LinkedChunk::updates`]: super::LinkedChunk::updates
|
||||
#[derive(Debug)]
|
||||
pub struct ObservableUpdates<Item, Gap> {
|
||||
pub(super) inner: Arc<RwLock<UpdatesInner<Item, Gap>>>,
|
||||
|
||||
@@ -3,7 +3,8 @@ use std::{borrow::Cow, fmt, path::Path, sync::Arc};
|
||||
use async_trait::async_trait;
|
||||
use deadpool_sqlite::{Object as SqliteAsyncConn, Pool as SqlitePool, Runtime};
|
||||
use matrix_sdk_base::{
|
||||
event_cache::store::EventCacheStore,
|
||||
event_cache::{store::EventCacheStore, Event, Gap},
|
||||
linked_chunk::Update,
|
||||
media::{MediaRequestParameters, UniqueKey},
|
||||
};
|
||||
use matrix_sdk_store_encryption::StoreCipher;
|
||||
@@ -182,6 +183,13 @@ impl EventCacheStore for SqliteEventCacheStore {
|
||||
Ok(num_touched == 1)
|
||||
}
|
||||
|
||||
async fn handle_linked_chunk_updates(
|
||||
&self,
|
||||
_updates: &[Update<Event, Gap>],
|
||||
) -> Result<(), Self::Error> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn add_media_content(
|
||||
&self,
|
||||
request: &MediaRequestParameters,
|
||||
|
||||
Reference in New Issue
Block a user