Skip to content

refactor: Move linked chunk into matrix-sdk-common and few event cache types into matrix-sdk-base #4247

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

Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use crate::RoomMemberships;
use crate::{
deserialized_responses::{RawAnySyncOrStrippedTimelineEvent, SyncTimelineEvent},
error::{Error, Result},
event_cache_store::EventCacheStoreLock,
event_cache::store::EventCacheStoreLock,
response_processors::AccountDataProcessor,
rooms::{
normal::{RoomInfoNotableUpdate, RoomInfoNotableUpdateReasons},
Expand Down
30 changes: 30 additions & 0 deletions crates/matrix-sdk-base/src/event_cache/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Event cache store and common types shared with `matrix_sdk::event_cache`.

use matrix_sdk_common::deserialized_responses::SyncTimelineEvent;

pub mod store;

/// The kind of event the event storage holds.
pub type Event = SyncTimelineEvent;

/// The kind of gap the event storage holds.
#[derive(Clone, Debug)]
pub struct Gap {
/// The token to use in the query, extracted from a previous "from" /
/// "end" field of a `/messages` response.
pub prev_token: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
///
/// ## Usage Example:
/// ```no_run
/// # use matrix_sdk_base::event_cache_store::{
/// # use matrix_sdk_base::event_cache::store::{
/// # EventCacheStore,
/// # MemoryStore as MyStore,
/// # Result as EventCacheStoreResult,
Expand All @@ -217,7 +217,9 @@ macro_rules! event_cache_store_integration_tests {
() => {
mod event_cache_store_integration_tests {
use matrix_sdk_test::async_test;
use $crate::event_cache_store::{EventCacheStoreIntegrationTests, IntoEventCacheStore};
use $crate::event_cache::store::{
EventCacheStoreIntegrationTests, IntoEventCacheStore,
};

use super::get_event_cache_store;

Expand Down Expand Up @@ -249,7 +251,7 @@ macro_rules! event_cache_store_integration_tests_time {
use std::time::Duration;

use matrix_sdk_test::async_test;
use $crate::event_cache_store::IntoEventCacheStore;
use $crate::event_cache::store::IntoEventCacheStore;

use super::get_event_cache_store;

Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod client;
pub mod debug;
pub mod deserialized_responses;
mod error;
pub mod event_cache_store;
pub mod event_cache;
pub mod latest_event;
pub mod media;
pub mod notification_settings;
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use tokio::sync::{broadcast, Mutex, RwLock};
use tracing::warn;

use crate::{
event_cache_store,
event_cache::store as event_cache_store,
rooms::{normal::RoomInfoNotableUpdate, RoomInfo, RoomState},
MinimalRoomMemberEvent, Room, RoomStateFilter, SessionMeta,
};
Expand Down
3 changes: 3 additions & 0 deletions crates/matrix-sdk-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ uniffi = ["dep:uniffi"]

[dependencies]
async-trait = { workspace = true }
eyeball-im = { workspace = true }
futures-core = { workspace = true }
futures-util = { workspace = true }
imbl = { workspace = true }
ruma = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/matrix-sdk-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod debug;
pub mod deserialized_responses;
pub mod executor;
pub mod failures_cache;
pub mod linked_chunk;
pub mod ring_buffer;
pub mod store_locks;
pub mod timeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#![allow(dead_code)]
#![allow(rustdoc::private_intra_doc_links)]

//! A linked chunk is the underlying data structure that holds all events.

Expand Down Expand Up @@ -56,7 +57,7 @@ macro_rules! assert_items_eq {
let chunk = $iterator .next().expect("next chunk (expect items)");
assert!(chunk.is_items(), "chunk should contain items");

let $crate::event_cache::linked_chunk::ChunkContent::Items(items) = chunk.content() else {
let $crate::linked_chunk::ChunkContent::Items(items) = chunk.content() else {
unreachable!()
};

Expand Down Expand Up @@ -934,7 +935,6 @@ impl ChunkIdentifierGenerator {
#[repr(transparent)]
pub struct ChunkIdentifier(u64);

#[cfg(test)]
impl PartialEq<u64> for ChunkIdentifier {
fn eq(&self, other: &u64) -> bool {
self.0 == *other
Expand Down Expand Up @@ -963,7 +963,7 @@ impl Position {
/// # Panic
///
/// This method will panic if it will underflow, i.e. if the index is 0.
pub(super) fn decrement_index(&mut self) {
pub fn decrement_index(&mut self) {
self.1 = self.1.checked_sub(1).expect("Cannot decrement the index because it's already 0");
}
}
Expand Down Expand Up @@ -1346,7 +1346,8 @@ where
}

/// A type representing what to do when the system has to handle an empty chunk.
pub(crate) enum EmptyChunk {
#[derive(Debug)]
pub enum EmptyChunk {
/// Keep the empty chunk.
Keep,

Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-sqlite/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use deadpool_sqlite::{CreatePoolError, PoolError};
#[cfg(feature = "event-cache")]
use matrix_sdk_base::event_cache_store::EventCacheStoreError;
use matrix_sdk_base::event_cache::store::EventCacheStoreError;
#[cfg(feature = "state-store")]
use matrix_sdk_base::store::StoreError as StateStoreError;
#[cfg(feature = "crypto-store")]
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-sqlite/src/event_cache_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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,
media::{MediaRequestParameters, UniqueKey},
};
use matrix_sdk_store_encryption::StoreCipher;
Expand Down Expand Up @@ -279,7 +279,7 @@ mod tests {
};

use matrix_sdk_base::{
event_cache_store::{EventCacheStore, EventCacheStoreError},
event_cache::store::{EventCacheStore, EventCacheStoreError},
event_cache_store_integration_tests, event_cache_store_integration_tests_time,
media::{MediaFormat, MediaRequestParameters, MediaThumbnailSettings},
};
Expand Down Expand Up @@ -387,7 +387,7 @@ mod encrypted_tests {
use std::sync::atomic::{AtomicU32, Ordering::SeqCst};

use matrix_sdk_base::{
event_cache_store::EventCacheStoreError, event_cache_store_integration_tests,
event_cache::store::EventCacheStoreError, event_cache_store_integration_tests,
event_cache_store_integration_tests_time,
};
use once_cell::sync::Lazy;
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/client/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ async fn build_indexeddb_store_config(

let store_config = {
tracing::warn!("The IndexedDB backend does not implement an event cache store, falling back to the in-memory event cache store…");
store_config.event_cache_store(matrix_sdk_base::event_cache_store::MemoryStore::new())
store_config.event_cache_store(matrix_sdk_base::event_cache::store::MemoryStore::new())
};

Ok(store_config)
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use imbl::Vector;
#[cfg(feature = "e2e-encryption")]
use matrix_sdk_base::crypto::store::LockableCryptoStore;
use matrix_sdk_base::{
event_cache_store::EventCacheStoreLock,
event_cache::store::EventCacheStoreLock,
store::{DynStateStore, ServerCapabilities},
sync::{Notification, RoomUpdates},
BaseClient, RoomInfoNotableUpdate, RoomState, RoomStateFilter, SendOutsideWasm, SessionMeta,
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use matrix_sdk_base::crypto::{
CryptoStoreError, DecryptorError, KeyExportError, MegolmError, OlmError,
};
use matrix_sdk_base::{
event_cache_store::EventCacheStoreError, Error as SdkBaseError, QueueWedgeError, RoomState,
event_cache::store::EventCacheStoreError, Error as SdkBaseError, QueueWedgeError, RoomState,
StoreError,
};
use reqwest::Error as ReqwestError;
Expand Down
1 change: 0 additions & 1 deletion crates/matrix-sdk/src/event_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use self::paginator::PaginatorError;
use crate::{client::WeakClient, Client};

mod deduplicator;
mod linked_chunk;
mod pagination;
mod room;

Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk/src/event_cache/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use std::{future::Future, ops::ControlFlow, sync::Arc, time::Duration};

use eyeball::Subscriber;
use matrix_sdk_base::deserialized_responses::SyncTimelineEvent;
use matrix_sdk_common::linked_chunk::ChunkContent;
use tokio::time::timeout;
use tracing::{debug, instrument, trace};

use super::{
linked_chunk::ChunkContent,
paginator::{PaginationResult, PaginatorState},
room::{
events::{Gap, RoomEvents},
Expand Down
20 changes: 5 additions & 15 deletions crates/matrix-sdk/src/event_cache/room/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,14 @@

use std::cmp::Ordering;

use matrix_sdk_common::deserialized_responses::SyncTimelineEvent;
pub use matrix_sdk_base::event_cache::{Event, Gap};
use matrix_sdk_common::linked_chunk::{
Chunk, ChunkIdentifier, EmptyChunk, Error, Iter, LinkedChunk, Position,
};
use ruma::OwnedEventId;
use tracing::{debug, error, warn};

use super::super::{
deduplicator::{Decoration, Deduplicator},
linked_chunk::{Chunk, ChunkIdentifier, EmptyChunk, Error, Iter, LinkedChunk, Position},
};

/// An alias for the real event type.
pub(crate) type Event = SyncTimelineEvent;

#[derive(Clone, Debug)]
pub struct Gap {
/// The token to use in the query, extracted from a previous "from" /
/// "end" field of a `/messages` response.
pub prev_token: String,
}
use super::super::deduplicator::{Decoration, Deduplicator};

const DEFAULT_CHUNK_CAPACITY: usize = 128;

Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk/src/send_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
//! no thumbnails):
//!
//! - The file's content is immediately cached in the
//! [`matrix_sdk_base::event_cache_store::EventCacheStore`], using an MXC ID
//! [`matrix_sdk_base::event_cache::store::EventCacheStore`], using an MXC ID
//! that is temporary and designates a local URI without any possible doubt.
//! - An initial media event is created and uses this temporary MXC ID, and
//! propagated as a local echo for an event.
Expand Down Expand Up @@ -139,7 +139,7 @@ use std::{

use as_variant::as_variant;
use matrix_sdk_base::{
event_cache_store::EventCacheStoreError,
event_cache::store::EventCacheStoreError,
media::MediaRequestParameters,
store::{
ChildTransactionId, DependentQueuedRequest, DependentQueuedRequestKind,
Expand Down
Loading