-
Notifications
You must be signed in to change notification settings - Fork 336
IndexedDB: split media content and media metadata into separate object stores in MediaStore
#5795
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
base: main
Are you sure you want to change the base?
IndexedDB: split media content and media metadata into separate object stores in MediaStore
#5795
Conversation
Signed-off-by: Michael Goldenberg <[email protected]>
…ed id Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…ations Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…le media content id Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…pe serializer Signed-off-by: Michael Goldenberg <[email protected]>
…nd its derivatives Signed-off-by: Michael Goldenberg <[email protected]>
…put_item_if} and its derivatives Signed-off-by: Michael Goldenberg <[email protected]>
… ranges Signed-off-by: Michael Goldenberg <[email protected]>
… content key Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…data keys Signed-off-by: Michael Goldenberg <[email protected]>
…eys by index Signed-off-by: Michael Goldenberg <[email protected]>
…ata keys via generalized fn Signed-off-by: Michael Goldenberg <[email protected]>
… metadata and media content stores Signed-off-by: Michael Goldenberg <[email protected]>
…ndexed Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…level media type Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
CodSpeed Performance ReportMerging #5795 will not alter performanceComparing Summary
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5795 +/- ##
==========================================
- Coverage 88.45% 88.45% -0.01%
==========================================
Files 360 360
Lines 100328 100328
Branches 100328 100328
==========================================
- Hits 88749 88745 -4
- Misses 7413 7418 +5
+ Partials 4166 4165 -1 ☔ View full report in Codecov by Sentry. |
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.
This looks pretty good, thanks for splitting this up into many small commits.
I wonder what you think about utilizing a different type for the IDs.
Besides that I left a couple of nits about consistent naming of the content ID.
crates/matrix-sdk-indexeddb/src/media_store/serializer/indexed_types.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-indexeddb/src/media_store/serializer/indexed_types.rs
Outdated
Show resolved
Hide resolved
|
Oh, another thing. Please add a changelog entry. |
So, I haven't left changelog entries on any of the pull requests in this series because none of this code is accessible outside of the crate at the moment. Have I been thinking about this correctly? I am happy to add a changelog, just want to make sure we're on the same page. |
This should improve the performance of the media access. As such it sounds like it would be a nice thing to announce to our users. |
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…metadata in IndexedDB Signed-off-by: Michael Goldenberg <[email protected]>
|
@poljar: I added a changelog entry, but this is now in conflict with |
Please wait with rebasing till we're dong with the review phase. |
|
Okay, tests don't seem to run when there is a conflict, so figured it might be worth doing it before. |
Background
This pull request is part of a series of pull requests to add a full IndexedDB implementation of the
EventCacheStoreandMediaStore(see #4617, #4996, #5090, #5138, #5226, #5274, #5343, #5384, #5406, #5414, #5497, #5506, #5540, #5574, #5603, #5676, #5682, #5749). This particular pull request changes the schema for how media is stored by splitting content and metadata into separate object stores.The reason for this change is that IndexedDB does not allow partial updates to existing objects. So, when content and metadata are stored in the same object store, updating a metadata field requires deserializing and re-serializing the entire object, which includes content that has the potential to be very large - e.g., an image, a document, etc.
Changes
Adding separate stores for content and metadata
The overarching change is to add two new object stores, one for content and one for metadata.
MediaContentThe content store is very straightforward and simply maps an identifier (
u64) to the content, illustrated in the type below.When storing a
MediaContentobject in IndexedDB, one must find an unusedu64. Currently, this is accomplished by querying the object store for the largest identifier, incrementing it, and then using it as the identifier for the desired object.Note that IndexedDB does offer auto-incrementing keys; however, it's not clear if it's possible to retrieve the generated key upon insertion into the database via
indexed_db_futures. So, one must ultimately query the database to get access to the key in a similar fashion to that described above.MediaMetadataThe metadata store is almost identical to the original media store, but contains some additional information for tracking the identifier and the size of the
MediaContent, as illustrated in the type below.When storing a
MediaMetadataobject in IndexedDB, one must first store theMediaContent. Once theMediaContentis stored, one can determine its identifier and its encoded size which can be used to populateMediaMetadata::content_idandMediaMetadata::content_size.Note that this means that retrieving
MediaContentviaMediaRequestParametersrequires two steps.MediaRequestParametersto retrieveMediaMetadataMediaMetadata::content_idto retrieveMediaContentRemoving original media store
After the two object stores above were created and the implementations of various functions were updated to use those object stores, the original media store and its associated types were removed. There is one exception, which is that the top-level
Mediatype was kept in place, as it proved to be a useful top-level abstraction.Tradeoffs
Improvements
These changes offer significant improvements on the following operations.
MediaStore::replace_media_key- changes request parameters - i.e., primary key - of mediaMediaStore::get_media_content- retrieves media by request parameters and sets last access timeMediaStore::get_media_content_for_uri- retrieves media by URI and sets the last access timeMediaStore::set_ignore_media_retention_policy- sets whether to ignore media retention policyPenalties
On the other hand, there are also some penalties due to the updated schema.
MediaStore::add_media_content- adds mediaMediaStore::get_media_content- retrieves media by request parameters and sets last access timeMediaStore::remove_media_content- removes media by request parametersMediaStore::get_media_content_for_uri- retrieves media by URI and sets the last access timeMediaStore::remove_media_content_for_uri- removes media by URIMediaStore::clean- clean store by removing oversized and old mediaConclusions
My feeling is that this implementation is an improvement overall. That being said, some benchmarking would offer a greater degree of confidence that
MediaStore::cleanhas not deteriorated significantly. If this is desired, we can pursue this to get a better sense of the penalty.In any case, I don't think it would be wise to return to a single object store, but perhaps there is some way to improve upon the split object stores.
Future Work
EventCacheStoreandMediaStoreoutside of thematrix-sdk-indexeddbSigned-off-by: Michael Goldenberg [email protected]