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
|
Hywan
left a comment
There was a problem hiding this comment.
Excellent work, as always. Thanks for the small commits and all the small clean up.
I've left few feedback. Eager to merge it!
| } | ||
|
|
||
| /// 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.
Events aren't uniquely indexed by their ID?
There was a problem hiding this comment.
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.
It does make sense, yes. Thanks for the explanation.
|
Thanks, only read the description, and this all looks great! |
Hywan
left a comment
There was a problem hiding this comment.
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 theLinkedChunkIdargument provided in a number ofEventCacheStorefunctions by making modifications to key formats in a number of object stores.Prior to #5182, many functions of
EventCacheStorewere provided aRoomIdargument. In order to accommodate the possibility of thread-based operations,LinkedChunkIdreplaced many of theRoomIdarguments. Then, in #5445, theThreadvariant was added toLinkedChunkIdand would require that implementations ofEventCacheStoreproperly handle thread-based operations.This issue was surfaced by @bnjbvr here.
Changes
LinkedChunkIdandOwnedLinkedChunkIdFor ease of use, I have made
OwnedLinkedChunkId::as_refaccessible outside of[#cfg(test)]contexts, as well as addingFromimplementations betweenLinkedChunkIdandOwnedLinkedChunkId. This also made it possible to consolidate theDisplayimplementation for these two types.Additionally, I have derived
SerializeandDeserializeonOwnedLinkedChunkIdin 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
RoomIdwithLinkedChunkId, with one exception:IndexedEventRelationKeystill uses aRoomIdin its key becauseEventCacheStore::find_event_relationsis provided with aRoomIdand not aLinkedChunkId.Due to other event-related functions also continuing to operate on
RoomIds rather thanLinkedChunkIds, a new index (and associated key) was added to the event object store.events_roomroomRoomId,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_testswas recreated inmatrix_sdk_indexeddb::event_cache_store::integration_testsand selectively chose tests based on what was properly implemented. This has now been removed and thisEventCacheStoreimplementation is now being tested against the integration tests inmatrix_sdk_base.Future Work
EventCacheStoreMediaSigned-off-by: Michael Goldenberg [email protected]