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

IndexedDB Event Store #4617

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

ospfranco
Copy link

This PR is WIP.

This PR is meant to add a EventCache store for the the matrix-sdk-indexeddb crate of the SDK meant to be used in WASM contexts. Similar to the sqlite implementation is supposed to provide a disk persisted implementation for storing Events in LinkedChunks.

It follows the general structure of matrix-sdk-indexeddb/src/crypto_store and matrix-sdk-indexeddb/src/state_store, a new module matrix-sdk-indexeddb/src/event_cache_store has been added.

There are still many TODOs and questions in the codebase to which I would appreciate some guidance from the SDK maintainers.

  • Public API changes documented in changelogs (optional)

Signed-off-by: Oscar Franco


/// Handles the functionality of serializing and encrypting data for the
/// indexeddb store.
pub struct IndexeddbSerializer {
Copy link
Author

Choose a reason for hiding this comment

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

Copy and paste from crypto_store not sure if a different serializer is needed or they can be merged and re-used by both modules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did we end up having to change this much, or is it a straight copy? If straight copy, is it possible to pull it into a shared mod?

migration_conflict_strategy: MigrationConflictStrategy,
}

impl IndexeddbEventCacheStoreBuilder {
Copy link
Author

Choose a reason for hiding this comment

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

Follows the same pattern as state_store, not sure if this is wanted or not.

Ok(())
}

async fn try_take_leased_lock(
Copy link
Author

Choose a reason for hiding this comment

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

Copy and paste from crypto_store. I could not find any info on what this "leased_lock" is.

Copy link
Member

@Hywan Hywan Feb 5, 2025

Choose a reason for hiding this comment

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

This is related to the cross-process lock, the doc is missing a high-level overview I think… Tell me if you need more info.

Copy link
Author

Choose a reason for hiding this comment

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

I just copied the same from the crypto_store, if you think it is fine as it is, then no need. It should just work, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Possible candidate to try to put into a shared mod as well.

};

// let store_config = {
Copy link
Author

Choose a reason for hiding this comment

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

Will be removed later

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.73%. Comparing base (3f71d9a) to head (c686f90).
Report is 173 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4617      +/-   ##
==========================================
+ Coverage   85.71%   85.73%   +0.01%     
==========================================
  Files         291      291              
  Lines       33323    33322       -1     
==========================================
+ Hits        28563    28568       +5     
+ Misses       4760     4754       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hywan
Copy link
Member

Hywan commented Feb 11, 2025

Be aware that #4632 is likely to create a non-negligible conflict with your patches. The new methods to load chunk from the event cache are going to be simpler and will allow to incrementally load the chunks.

@ospfranco
Copy link
Author

Be aware that #4632 is likely to create a non-negligible conflict with your patches. The new methods to load chunk from the event cache are going to be simpler and will allow to incrementally load the chunks.

Ah, interesting... well... maybe it's worth to put this a bit on hold until that is merged. If the trait will be easier to implement, then it's worth it

@Hywan
Copy link
Member

Hywan commented Feb 11, 2025

The trait will gain 2 new methods: load_last_chunk and load_previous_chunk, and the method used to load the entire LinkedChunk is for testing-purposes only. So yeah, it's a bit simpler but it needs the whole package :-/.

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?

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?

match frm {
IndexeddbEventCacheStoreError::Json(e) => CryptoStoreError::Serialization(e),
IndexeddbEventCacheStoreError::CryptoStoreError(e) => e,
_ => 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/

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?


/// Handles the functionality of serializing and encrypting data for the
/// indexeddb store.
pub struct IndexeddbSerializer {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we end up having to change this much, or is it a straight copy? If straight copy, is it possible to pull it into a shared mod?

/// Return all the raw components of a linked chunk, so the caller may
/// reconstruct the linked chunk later.
async fn reload_linked_chunk(&self, _room_id: &RoomId) -> Result<Vec<RawChunk<Event, Gap>>> {
Ok(vec![])
Copy link
Contributor

Choose a reason for hiding this comment

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

todo!, or this is just for tests?

/// This will empty and remove all the linked chunks stored previously,
/// using the above [`Self::handle_linked_chunk_updates`] methods.
async fn clear_all_rooms_chunks(&self) -> Result<()> {
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

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

todo!, this should just be clearing the tables right?

_content: Vec<u8>,
_ignore_policy: IgnoreMediaRetentionPolicy,
) -> Result<()> {
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

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

Media content seems much simpler than the chunk system, is that correct?

Ok(())
}

async fn try_take_leased_lock(
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible candidate to try to put into a shared mod as well.

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())
let event_cache_store = matrix_sdk_indexeddb::open_event_cache_store(name, None).await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like sqlite uses the same passphrase for both stores, should we do the same here instead of passing None?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants