Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
cd61f3c
feat(linked chunk): expose OwnedLinkedChunkId::as_ref for use in othe…
mgoldenberg Aug 14, 2025
76d036e
feat(linked chunk): add trait-based conversions between owned and bor…
mgoldenberg Aug 14, 2025
84f0778
feat(linked chunk): add display impl for LinkedChunkId
mgoldenberg Aug 14, 2025
54652da
feat(linked chunk): derive ser/de traits for OwnedLinkedChunkId
mgoldenberg Aug 14, 2025
bd817d4
refactor(indexeddb): expose hash_key fn in serializer for keys repres…
mgoldenberg Aug 14, 2025
a86abaf
refactor(indexeddb): add room-based index to event object store in pr…
mgoldenberg Aug 15, 2025
5643742
refactor(indexeddb): use room-based queries in event-related fns that…
mgoldenberg Aug 15, 2025
9ec058f
refactor(indexeddb): re-organize type synonyms in event_cache_store::…
mgoldenberg Aug 15, 2025
07f8fe3
fix(indexeddb): integrate linked chunk id into relevant event-related…
mgoldenberg Aug 15, 2025
6565f72
fix(indexeddb): integrate linked chunk id into relevant chunk- and ga…
mgoldenberg Aug 15, 2025
17fc251
test(indexeddb): use event cache store integration tests from matrix_…
mgoldenberg Aug 15, 2025
a4edef1
refactor(indexeddb): log linked chunk id rather than room id in handl…
mgoldenberg Aug 15, 2025
1e2bc5a
docs(indexeddb): remove references to room where relevant in transact…
mgoldenberg Aug 17, 2025
d210e60
docs(indexeddb): correct key docs to express that keys are hashed, no…
mgoldenberg Aug 17, 2025
82faedd
style(indexeddb): format event cache store impl by temporarily removi…
mgoldenberg Aug 17, 2025
03d02d7
refactor(indexeddb): allow IndexeddbSerializer::hash_key to be unused…
mgoldenberg Aug 17, 2025
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
36 changes: 27 additions & 9 deletions crates/matrix-sdk-common/src/linked_chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ use std::{
pub use as_vector::*;
pub use order_tracker::OrderTracker;
use ruma::{EventId, OwnedEventId, OwnedRoomId, RoomId};
use serde::{Deserialize, Serialize};
pub use updates::*;

/// An identifier for a linked chunk; borrowed variant.
Expand All @@ -116,6 +117,17 @@ pub enum LinkedChunkId<'a> {
Thread(&'a RoomId, &'a EventId),
}

impl Display for LinkedChunkId<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Room(room_id) => write!(f, "{room_id}"),
Self::Thread(room_id, thread_root) => {
write!(f, "{room_id}:thread:{thread_root}")
}
}
}
}

impl LinkedChunkId<'_> {
pub fn storage_key(&self) -> impl '_ + AsRef<[u8]> {
match self {
Expand All @@ -134,6 +146,12 @@ impl LinkedChunkId<'_> {
}
}

impl<'a> From<&'a OwnedLinkedChunkId> for LinkedChunkId<'a> {
fn from(value: &'a OwnedLinkedChunkId) -> Self {
value.as_ref()
}
}

impl PartialEq<&OwnedLinkedChunkId> for LinkedChunkId<'_> {
fn eq(&self, other: &&OwnedLinkedChunkId) -> bool {
match (self, other) {
Expand All @@ -154,26 +172,20 @@ impl PartialEq<LinkedChunkId<'_>> for OwnedLinkedChunkId {
}

/// An identifier for a linked chunk; owned variant.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum OwnedLinkedChunkId {
Room(OwnedRoomId),
Thread(OwnedRoomId, OwnedEventId),
}

impl Display for OwnedLinkedChunkId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
OwnedLinkedChunkId::Room(room_id) => write!(f, "{room_id}"),
OwnedLinkedChunkId::Thread(room_id, thread_root) => {
write!(f, "{room_id}:thread:{thread_root}")
}
}
self.as_ref().fmt(f)
}
}

impl OwnedLinkedChunkId {
#[cfg(test)]
fn as_ref(&self) -> LinkedChunkId<'_> {
pub fn as_ref(&self) -> LinkedChunkId<'_> {
match self {
OwnedLinkedChunkId::Room(room_id) => LinkedChunkId::Room(room_id.as_ref()),
OwnedLinkedChunkId::Thread(room_id, event_id) => {
Expand All @@ -190,6 +202,12 @@ impl OwnedLinkedChunkId {
}
}

impl From<LinkedChunkId<'_>> for OwnedLinkedChunkId {
fn from(value: LinkedChunkId<'_>) -> Self {
value.to_owned()
}
}

/// Errors of [`LinkedChunk`].
#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,98 +684,3 @@ macro_rules! indexeddb_event_cache_store_integration_tests {
}
};
}

// This is copied from `matrix_sdk_base::event_cache::store::integration_tests`
// for the time being, because the IndexedDB implementation of `EventCacheStore`
// is being completed iteratively. So, we are only bringing over the tests
// relevant to the implemented functions. At the moment, this includes the
// following.
//
// - EventCacheStore::handle_linked_chunk_updates
// - EventCacheStore::load_all_chunks
//
// When all functions are implemented, we can get rid of this macro and use the
// one from `matrix_sdk_base`.
#[macro_export]
macro_rules! event_cache_store_integration_tests {
() => {
mod event_cache_store_integration_tests {
use matrix_sdk_base::event_cache::store::{
EventCacheStoreIntegrationTests, IntoEventCacheStore,
};
use matrix_sdk_test::async_test;

use super::get_event_cache_store;

#[async_test]
async fn test_handle_updates_and_rebuild_linked_chunk() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_handle_updates_and_rebuild_linked_chunk().await;
}

#[async_test]
async fn test_linked_chunk_incremental_loading() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_linked_chunk_incremental_loading().await;
}

#[async_test]
async fn test_rebuild_empty_linked_chunk() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_rebuild_empty_linked_chunk().await;
}

#[async_test]
async fn test_load_all_chunks_metadata() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_load_all_chunks_metadata().await;
}

#[async_test]
async fn test_clear_all_linked_chunks() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_clear_all_linked_chunks().await;
}

#[async_test]
async fn test_remove_room() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_remove_room().await;
}

#[async_test]
async fn test_filter_duplicated_events() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_filter_duplicated_events().await;
}

#[async_test]
async fn test_find_event() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_find_event().await;
}

#[async_test]
async fn test_find_event_relations() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_find_event_relations().await;
}

#[async_test]
async fn test_save_event() {
let event_cache_store =
get_event_cache_store().await.unwrap().into_event_cache_store();
event_cache_store.test_save_event().await;
}
}
};
}
12 changes: 12 additions & 0 deletions crates/matrix-sdk-indexeddb/src/event_cache_store/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,15 @@ pub mod v1 {
pub const LEASES: &str = "leases";
pub const LEASES_KEY_PATH: &str = "id";
pub const ROOMS: &str = "rooms";
pub const LINKED_CHUNK_IDS: &str = "linked_chunk_ids";
pub const LINKED_CHUNKS: &str = "linked_chunks";
pub const LINKED_CHUNKS_KEY_PATH: &str = "id";
pub const LINKED_CHUNKS_NEXT: &str = "linked_chunks_next";
pub const LINKED_CHUNKS_NEXT_KEY_PATH: &str = "next";
pub const EVENTS: &str = "events";
pub const EVENTS_KEY_PATH: &str = "id";
pub const EVENTS_ROOM: &str = "events_room";
pub const EVENTS_ROOM_KEY_PATH: &str = "room";
pub const EVENTS_POSITION: &str = "events_position";
pub const EVENTS_POSITION_KEY_PATH: &str = "position";
pub const EVENTS_RELATION: &str = "events_relation";
Expand Down Expand Up @@ -169,6 +172,7 @@ pub mod v1 {
/// Create an object store for tracking information about events.
///
/// * Primary Key - `id`
/// * Index (unique) - `room` - tracks whether an event is in a given room
/// * Index (unique) - `position` - tracks position of an event in linked
/// chunks
/// * Index - `relation` - tracks any event to which the given event is
Expand All @@ -178,6 +182,14 @@ pub mod v1 {
object_store_params.key_path(Some(&keys::EVENTS_KEY_PATH.into()));
let events = db.create_object_store_with_params(keys::EVENTS, &object_store_params)?;

let events_room_params = IdbIndexParameters::new();
events_room_params.set_unique(true);
events.create_index_with_params(
keys::EVENTS_ROOM,
&keys::EVENTS_ROOM_KEY_PATH.into(),
&events_room_params,
);

let events_position_params = IdbIndexParameters::new();
events_position_params.set_unique(true);
events.create_index_with_params(
Expand Down
Loading
Loading