Skip to content
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

feat(event cache store): add an IndexedDB implementation #4617

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6955428
Modify the matrix-sdk and add feature flag for the event cache store
ospfranco Jan 30, 2025
b8bfd3e
Create the basic struct to initialize an event_cache_store
ospfranco Jan 30, 2025
c2761d5
Almost working instantiation of event cache store
ospfranco Jan 30, 2025
3c6ca6a
Fix deps on feature indexeddb
ospfranco Jan 31, 2025
7eb8946
Add license text at top
ospfranco Jan 31, 2025
64e68ba
Copy try_take_leased_lock from crypto_store impl
ospfranco Jan 31, 2025
1328003
Add missing methods from EventCacheTrait
ospfranco Jan 31, 2025
eebe00e
Fix a bunch of errors, move error to it's own file
ospfranco Feb 3, 2025
e49bda6
Fix final errors around creating the event cache store
ospfranco Feb 3, 2025
1b1029d
First insertion into indexeddb
ospfranco Feb 3, 2025
c317bd8
Merge branch 'main' into oscar/indexeddb-event-cache-store
ospfranco Feb 4, 2025
0f8ebf1
Finish implementing insert_chunk
ospfranco Feb 4, 2025
ee40ddd
Comment unused code, finish implementing insert_chunk
ospfranco Feb 4, 2025
73713ac
Get rid of name param
ospfranco Feb 4, 2025
d3b6f87
Insert GAP chunk
ospfranco Feb 4, 2025
8528522
Tried to implement insert gap, but missing encode_value on serializer
ospfranco Feb 4, 2025
7622be4
Implement insert gap
ospfranco Feb 6, 2025
01cb5ba
remove chunk deletes from LINKED_CHUNKS store, missing related entities
ospfranco Feb 6, 2025
8f2b427
Fix some compilation errors
ospfranco Feb 10, 2025
722bac2
PushItems
ospfranco Feb 10, 2025
4ca221f
PushItems
ospfranco Feb 10, 2025
0e05ac8
RemoteItem
ospfranco Feb 10, 2025
28647b6
Half implementation of DetachLastItems
ospfranco Feb 10, 2025
eee0bad
Remove deletion
ospfranco Feb 10, 2025
0b0e15e
Add placeholder for deletion
ospfranco Feb 10, 2025
993283c
Change previous implementations to use serializer
ospfranco Feb 11, 2025
d755cc0
Change previous implementations to use serializer
ospfranco Feb 11, 2025
abee3ab
Do not interate through get_all_with_key
ospfranco Feb 11, 2025
06b0395
Fix encoded room id as ref
ospfranco Feb 13, 2025
ae25b35
finish DetachLastItems
ospfranco Feb 13, 2025
4dcf22a
PushItems now uses TimeEventForCache struct
ospfranco Feb 13, 2025
610860b
Implement Update::Clear
ospfranco Feb 13, 2025
ebda277
Fixes on initialization of event-cache store
ospfranco Feb 17, 2025
1af016f
WIP, fixes for creating serializable objects
ospfranco Feb 17, 2025
6d8b405
More fixes on serialization and deserialization
ospfranco Feb 17, 2025
4179750
Working retrieving of events
ospfranco Feb 20, 2025
6c7b729
Update key handling
ospfranco Feb 21, 2025
c686f90
Fix ranges
ospfranco Feb 21, 2025
8cfe19c
Add stub for tests
ospfranco Feb 24, 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
3 changes: 2 additions & 1 deletion crates/matrix-sdk-indexeddb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ default-target = "wasm32-unknown-unknown"
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["e2e-encryption", "state-store"]
default = ["e2e-encryption", "state-store", "event-cache-store"]
state-store = ["dep:matrix-sdk-base", "growable-bloom-filter"]
event-cache-store = ["dep:matrix-sdk-base", "dep:matrix-sdk-crypto"]
e2e-encryption = ["dep:matrix-sdk-crypto"]
testing = ["matrix-sdk-crypto?/testing"]

Expand Down
69 changes: 69 additions & 0 deletions crates/matrix-sdk-indexeddb/src/event_cache_store/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use matrix_sdk_base::{event_cache::store::EventCacheStoreError, StoreError};
use matrix_sdk_crypto::store::CryptoStoreError;
use matrix_sdk_store_encryption::Error as EncryptionError;

#[derive(Debug, thiserror::Error)]
pub enum IndexeddbEventCacheStoreError {
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error(transparent)]
Encryption(#[from] EncryptionError),
#[error("DomException {name} ({code}): {message}")]
DomException { name: String, message: String, code: u16 },
#[error(transparent)]
StoreError(#[from] StoreError),
#[error("Can't migrate {name} from {old_version} to {new_version} without deleting data. See MigrationConflictStrategy for ways to configure.")]
MigrationConflict { name: String, old_version: u32, new_version: u32 },
#[error(transparent)]
CryptoStoreError(#[from] CryptoStoreError),
}

impl From<web_sys::DomException> for IndexeddbEventCacheStoreError {
fn from(frm: web_sys::DomException) -> IndexeddbEventCacheStoreError {
IndexeddbEventCacheStoreError::DomException {
name: frm.name(),
message: frm.message(),
code: frm.code(),
}
}
}

impl From<IndexeddbEventCacheStoreError> for StoreError {
fn from(e: IndexeddbEventCacheStoreError) -> Self {
match e {
IndexeddbEventCacheStoreError::Json(e) => StoreError::Json(e),
IndexeddbEventCacheStoreError::StoreError(e) => e,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this compile, I'm surprised it doesn't need a wrapper for StoreError here?

IndexeddbEventCacheStoreError::Encryption(e) => StoreError::Encryption(e),
_ => StoreError::backend(e),
}
}
}

impl From<IndexeddbEventCacheStoreError> for EventCacheStoreError {
fn from(e: IndexeddbEventCacheStoreError) -> Self {
match e {
IndexeddbEventCacheStoreError::Json(e) => EventCacheStoreError::Serialization(e),
IndexeddbEventCacheStoreError::StoreError(e) => {
EventCacheStoreError::Backend(Box::new(e))
}
IndexeddbEventCacheStoreError::Encryption(e) => EventCacheStoreError::Encryption(e),
_ => EventCacheStoreError::backend(e),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backend => Backend, right?

}
}
}

impl From<IndexeddbEventCacheStoreError> for CryptoStoreError {
fn from(frm: IndexeddbEventCacheStoreError) -> CryptoStoreError {
match frm {
IndexeddbEventCacheStoreError::Json(e) => CryptoStoreError::Serialization(e),
IndexeddbEventCacheStoreError::CryptoStoreError(e) => e,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think this needs a wrapper as well, right?

_ => CryptoStoreError::backend(frm),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/backend/Backend/

}
}
}

impl From<serde_wasm_bindgen::Error> for IndexeddbEventCacheStoreError {
fn from(e: serde_wasm_bindgen::Error) -> Self {
IndexeddbEventCacheStoreError::Json(serde::de::Error::custom(e.to_string()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use gloo_utils::format::JsValueSerdeExt;
use indexed_db_futures::idb_object_store::IdbObjectStore;
use serde::{Deserialize, Serialize};
use wasm_bindgen::JsValue;

#[derive(Serialize, Deserialize)]
struct Chunk {
id: String,
previous: Option<u64>,
new: u64,
next: Option<u64>,
}

pub async fn insert_chunk(
store: IdbObjectStore<'_>,
hashed_room_id: &String,
previous: Option<u64>,
new: u64,
next: Option<u64>,
) -> Result<(), web_sys::DomException> {
let id = format!("{}-{}", hashed_room_id, new);
let chunk = Chunk { id, previous, new, next };
let value = JsValue::from_serde(&chunk).unwrap();
store.add_val(&value)?;
Ok(())
}
Loading
Loading