IndexedDB: remove assumption that all EventCacheStore keys contain a RoomId#5497
Conversation
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…mponents Signed-off-by: Michael Goldenberg <[email protected]>
…t key component bounds Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…Event Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…:Bound to loosen constraints on various functions Signed-off-by: Michael Goldenberg <[email protected]>
…rg to IndexedKey::encode Signed-off-by: Michael Goldenberg <[email protected]>
…zer and transaction fns Signed-off-by: Michael Goldenberg <[email protected]>
…ith_related_event_id Signed-off-by: Michael Goldenberg <[email protected]>
…t_events_by_related_event Signed-off-by: Michael Goldenberg <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5497 +/- ##
=======================================
Coverage 88.93% 88.93%
=======================================
Files 335 335
Lines 93274 93274
Branches 93274 93274
=======================================
+ Hits 82949 82957 +8
+ Misses 6462 6454 -8
Partials 3863 3863 ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #5497 will not alter performanceComparing Summary
|
andybalaam
left a comment
There was a problem hiding this comment.
This all sounds very sensible, and the code looks like it does what is described, but I definitely need Ivan to weigh in on the direction, since he has already been involved in this.
Thanks for the small commits! Very helpful.
Hywan
left a comment
There was a problem hiding this comment.
What can I say? PR description is clear. Commits are clear. Code is great.
Bravo 👏 !
| impl<'a, T, K, P> IndexedPrefixKeyBounds<T, P> for K | ||
| where | ||
| T: Indexed, | ||
| K: IndexedPrefixKeyComponentBounds<'a, T, P> + Sized, | ||
| P: 'a, | ||
| { | ||
| fn lower_key_with_prefix(prefix: P, serializer: &IndexeddbSerializer) -> Self { | ||
| <Self as IndexedKey<T>>::encode(Self::lower_key_components_with_prefix(prefix), serializer) | ||
| } | ||
|
|
||
| fn upper_key_with_prefix(prefix: P, serializer: &IndexeddbSerializer) -> Self { | ||
| <Self as IndexedKey<T>>::encode(Self::upper_key_components_with_prefix(prefix), serializer) | ||
| } | ||
| } |
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). This particular pull request focuses on removing the assumption that allEventCacheStorekeys contain aRoomId. This refactoring is necessary in order to support the queries related to leases and media, which make no reference to rooms - e.g., here, here, here, etc.Changes
No References to
RoomIdin Serialization TraitsThe overarching change is that each of the traits in
event_cache_store::serializer::traitsno longer makes reference to aRoomId, which ultimately lays the foundation for keys which do not contain aRoomId. For the existing keys - all of which contain aRoomId- their components are now fully represented inIndexedKey::KeyComponents.So, for instance,
IndexedChunkIdKeypreviously had the following implementation.But now, has an updated implementation.
Additional Traits for Representing Prefix Keys
By encoding the
RoomIdas an element ofIndexedKey::KeyComponents, the traitIndexedKeyComponentBounds, which expresses the bounds of the key components, now includes the lower and upper bounds of theRoomIdas well. This becomes insufficient as the existing queries are always minimally searching within the bounds of a single room.Consequently, I have added a trait for constructing key components bounds that allows one to hold leading components constant, while providing bounds on the remaining components. So,
IndexedKeyComponentBoundsis supplemented byIndexedPrefixKeyComponentBoundsshown below.Let's again consider
IndexedChunkIdKey. Previously, this key had an implementation ofIndexedKeyComponentBounds, shown below.When
RoomIdbecomes a key component, the functions above would provide us with the lower and upper bounds of keys for all chunks in all rooms.Alternatively, a relevant implementation of
IndexedPrefixKeyComponentBoundscan provide us with the lower and upper bounds of keys for all chunks in a single room.Propogate Changes
The remaining changes are simply propogations of the changes outlined above. These include adding and removing references to
RoomIdwhere necessary, modifying type constraints on certain generalized functions, etc.Future Work
LinkedChunkId(see here).EventCacheStore::try_take_leased_lockfunctions without relying onMemoryStoreEventCacheStoreMediaSigned-off-by: Michael Goldenberg [email protected]