-
Notifications
You must be signed in to change notification settings - Fork 332
IndexedDB: handle LinkedChunkId
properly in EventCacheStore
implementation
#5540
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: handle LinkedChunkId
properly in EventCacheStore
implementation
#5540
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5540 +/- ##
==========================================
- Coverage 88.59% 88.59% -0.01%
==========================================
Files 340 340
Lines 93850 93859 +9
Branches 93850 93859 +9
==========================================
+ Hits 83147 83150 +3
- Misses 6571 6578 +7
+ Partials 4132 4131 -1 ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #5540 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, as always. Thanks for the small commits and all the small clean up.
I've left few feedback. Eager to merge it!
@@ -601,6 +602,17 @@ impl<'a> IndexeddbEventCacheStoreTransaction<'a> { | |||
self.get_item_by_key::<Event, IndexedEventIdKey>(key).await | |||
} | |||
|
|||
/// Query IndexedDB for events that match the given event id in the given | |||
/// room. If more than one item is found, an error is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Events aren't uniquely indexed by their ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, they are uniquely indexed by their ID!
That being said, the IndexedDB API's function for getting a single value - i.e., IDBObjectStore.get
- from an object store will return the "first record matching the given key". Consequently, I have no way of knowing whether the returned record from calling this function was the one and only record or the first of a set of records.
So, throughout the codebase, I opt for getting a set of records and then verifying that there is only one. That way, if for some reason I forgot to make a particular index unique, requests for a single value that should be unique but actually match multiple records do not go unnoticed.
Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does make sense, yes. Thanks for the explanation.
Thanks, only read the description, and this all looks great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rebase the fixup commits, we are good!
…r crates Signed-off-by: Michael Goldenberg <[email protected]>
…rowed linked chunk id Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…ented as bytes rather than strings Signed-off-by: Michael Goldenberg <[email protected]>
…eparation for linked chunk id as primary key Signed-off-by: Michael Goldenberg <[email protected]>
… don't use linked chunk ids Signed-off-by: Michael Goldenberg <[email protected]>
…serializer Signed-off-by: Michael Goldenberg <[email protected]>
… types and fns Signed-off-by: Michael Goldenberg <[email protected]>
…p-related types and fns Signed-off-by: Michael Goldenberg <[email protected]>
…sdk_base Signed-off-by: Michael Goldenberg <[email protected]>
…e_linked_chunk_updates Signed-off-by: Michael Goldenberg <[email protected]>
…ion docs Signed-off-by: Michael Goldenberg <[email protected]>
…t encrypted Signed-off-by: Michael Goldenberg <[email protected]>
…ng enclosing macro Signed-off-by: Michael Goldenberg <[email protected]>
… until event cache store is a default feature Signed-off-by: Michael Goldenberg <[email protected]>
563f573
to
03d02d7
Compare
Background
This pull request is part of a series of pull requests to add a full IndexedDB implementation of the
EventCacheStore
(see #4617, #4996, #5090, #5138, #5226, #5274, #5343, #5384, #5406, #5414, #5497, #5506). This particular pull request adds proper handling of theLinkedChunkId
argument provided in a number ofEventCacheStore
functions by making modifications to key formats in a number of object stores.Prior to #5182, many functions of
EventCacheStore
were provided aRoomId
argument. In order to accommodate the possibility of thread-based operations,LinkedChunkId
replaced many of theRoomId
arguments. Then, in #5445, theThread
variant was added toLinkedChunkId
and would require that implementations ofEventCacheStore
properly handle thread-based operations.This issue was surfaced by @bnjbvr here.
Changes
LinkedChunkId
andOwnedLinkedChunkId
For ease of use, I have made
OwnedLinkedChunkId::as_ref
accessible outside of[#cfg(test)]
contexts, as well as addingFrom
implementations betweenLinkedChunkId
andOwnedLinkedChunkId
. This also made it possible to consolidate theDisplay
implementation for these two types.Additionally, I have derived
Serialize
andDeserialize
onOwnedLinkedChunkId
in order to allow this type to be easily stored in a database, e.g., IndexedDB.Note that these changes were discussed with @bnjbvr, though he may want to give final confirmation that this is aligned with his intention for the types.
Keys and Indices
All existing keys replace
RoomId
withLinkedChunkId
, with one exception:IndexedEventRelationKey
still uses aRoomId
in its key becauseEventCacheStore::find_event_relations
is provided with aRoomId
and not aLinkedChunkId
.Due to other event-related functions also continuing to operate on
RoomId
s rather thanLinkedChunkId
s, a new index (and associated key) was added to the event object store.events_room
room
RoomId
,EventId
)This index (and key) are necessary to support the following operations.
EventCacheStore::find_event
- finds an event in a particular room.EventCacheStore::save_event
- saves an event to a particular room.Tests
Up until this pull request,
matrix_sdk_base::event_cache_store_integration_tests
was recreated inmatrix_sdk_indexeddb::event_cache_store::integration_tests
and selectively chose tests based on what was properly implemented. This has now been removed and thisEventCacheStore
implementation is now being tested against the integration tests inmatrix_sdk_base
.Future Work
EventCacheStoreMedia
Signed-off-by: Michael Goldenberg [email protected]