-
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
Open
mgoldenberg
wants to merge
32
commits into
matrix-org:main
Choose a base branch
from
mgoldenberg:indexeddb-media-store-separate-metadata-and-content
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
IndexedDB: split media content and media metadata into separate object stores in MediaStore
#5795
mgoldenberg
wants to merge
32
commits into
matrix-org:main
from
mgoldenberg:indexeddb-media-store-separate-metadata-and-content
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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]