Skip to content

Conversation

@mgoldenberg
Copy link
Contributor

Background

This pull request is part of a series of pull requests to add an IndexedDB implementation of the EventCacheStore (see #4617, #4996, #5090). This particular pull request provides initial types and a database schema.

Changes

This change does not expose any code, but simply adds the initial types and migrations that will be used in the implementation of EventCacheStore. Ideally, the schema would mimic the one used in the SQLite implementation of EventCacheStore, but given that IndexedDB is not relational, the schema needed some modification.

Queries

The following queries are used in the implementation of EventCacheStore and so, must be supported in our schema.

  1. RoomId → Next ChunkIdentifier
  2. RoomId, ChunkIdentifier → All Events in corresponding Chunk
  3. RoomId → Last Chunk in LinkedChunks
  4. RoomId, EventIdEvent
  5. RoomId, EventIdPosition, if any, in LinkedChunks
  6. RoomId, EventId, RelationType → All Events related to EventId by RelationType

Schema

  • CORE - Object store
    • No primary key, used for dealing with leases and other miscellaneous data
  • LINKED_CHUNKS - Object store
    • Key - id - composed of RoomId and ChunkIdentifier
    • Value - object representing a Chunk
    • Supports queries (1), (2)
  • LINKED_CHUNKS_NEXT - Index on LINKED_CHUNKS
    • Key - next - composed of RoomId and ChunkIdentifier
    • Value - same as LINKED_CHUNKS
    • Supports query (3)
  • EVENTS - Object store
    • Key - id - composed of RoomId and EventId
    • Value - object representing an Event
    • Supports queries (4)
  • EVENTS_POSITION - Index on EVENTS
    • Key - position - composed of RoomId and ChunkIdentifier
    • Value - same as EVENTS
    • Supports query (5)
  • EVENTS_RELATION - Index on EVENTS
    • Key - relation - composed of RoomId, EventId, RelationType
    • Value - same as EVENTS
    • Supports query (6)

Types

There are two sets of types which will be used for performing various operations.

  1. event_cache_store::types - decrypted, used for high-level operations on the data itself
  2. event_cache_store::serializer::types - may be encrypted, used to store encoded data but exposes certain values for effective querying

These types will have implicit conversions from one to the other during (de)serialization, however, that is not included in this pull request.

Future Work

  • Add conversions and (de)serialization functions for all types in event_cache_store::types
  • Add implementation of EventCacheStore which uses these types

  • Public API changes documented in changelogs (optional)

Signed-off-by: Michael Goldenberg [email protected]

@mgoldenberg mgoldenberg requested a review from a team as a code owner May 30, 2025 00:05
@mgoldenberg mgoldenberg requested review from Hywan and removed request for a team May 30, 2025 00:05
@codecov
Copy link

codecov bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.16%. Comparing base (f3f3d96) to head (922ea91).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5138      +/-   ##
==========================================
+ Coverage   85.15%   85.16%   +0.01%     
==========================================
  Files         329      329              
  Lines       36923    36923              
==========================================
+ Hits        31442    31447       +5     
+ Misses       5481     5476       -5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

Pretty cool! I have a couple of tiny feedback. Other than that, it's good and easy to follow. Thanks! I'm enjoying the code structure.

@mgoldenberg
Copy link
Contributor Author

mgoldenberg commented Jun 5, 2025

By the way, I made one additional change aside from those you requested.

Basically, the change is that GenericEvent now allows us to enforce a type-level distinction between in-band and out-of-band events. This is accomplished by making GenericEvent::position a required field, as opposed to an Option, as an Option only enforces a value distinction.

pub struct GenericEvent<P> {
    ...,
    pub position: Option<P>, // => position: P
}

pub type InBandEvent = GenericEvent<Position>;
pub type OutOfBandEvent = GenericEvent<()>;

This is already the case in another branch where I have all my changes, but I must have made a mistake when copying the code over into this branch.

@mgoldenberg mgoldenberg requested a review from Hywan June 5, 2025 02:13
Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

A couple of feedback regarding the doc, and a more robust Version enum to replace u32. Other than that, we are good!

@mgoldenberg mgoldenberg requested a review from Hywan June 6, 2025 16:35
@mgoldenberg
Copy link
Contributor Author

@Hywan, sorry about the last minute changes after re-requesting a review 😬 I am working on the implementation in a separate branch, and realized some of the types should change slightly.

At any rate, I figured I might be able to sneak those changes in before you review - hope that's okay!

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

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

All good to me! Congrats and thank you very much. Can you rebase your history please? Or would you prefer we squash everything on our side?

…ndexing in event cache store

Signed-off-by: Michael Goldenberg <[email protected]>
…ndexing in event cache store

Signed-off-by: Michael Goldenberg <[email protected]>
…in-band/out-of-band events

Signed-off-by: Michael Goldenberg <[email protected]>
…tifiers rather than entire chunks

Signed-off-by: Michael Goldenberg <[email protected]>
…ng for compatibility with SafeEncode

Signed-off-by: Michael Goldenberg <[email protected]>
…dexedDB supports numeric keys

Signed-off-by: Michael Goldenberg <[email protected]>
…next chunk does not exist

Signed-off-by: Michael Goldenberg <[email protected]>
@mgoldenberg mgoldenberg force-pushed the indexeddb-event-cache-store-schema branch from 51b302e to 922ea91 Compare June 11, 2025 13:51
@mgoldenberg
Copy link
Contributor Author

I rebased - hopefully everything passes!

@Hywan Hywan merged commit 404a982 into matrix-org:main Jun 11, 2025
43 checks passed
@mgoldenberg mgoldenberg deleted the indexeddb-event-cache-store-schema branch June 11, 2025 19:17
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.

2 participants