-
Notifications
You must be signed in to change notification settings - Fork 332
IndexedDB: add functionality for cleaning up MediaStore
#5749
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: add functionality for cleaning up MediaStore
#5749
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5749 +/- ##
=======================================
Coverage 88.42% 88.42%
=======================================
Files 360 360
Lines 99796 99796
Branches 99796 99796
=======================================
+ Hits 88244 88246 +2
+ Misses 7411 7410 -1
+ Partials 4141 4140 -1 ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #5749 will not alter performanceComparing Summary
|
(Test failure is due to an intermittent timing issue in how |
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.
Thanks, looks good! Mostly small nits here and there, so will merge after they've been addressed.
Great work there 👍
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
crates/matrix-sdk-indexeddb/src/media_store/serializer/indexed_types.rs
Outdated
Show resolved
Hide resolved
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.
lgtm, thanks. Do you want to squash the fixup commits, or should I squash the entire PR into a single commit? I'm fine both ways.
Ivan has opted for squashing the fixup commits for the other pull requests, so let's stick with that! Let me know if you want me to rebase! |
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]>
…media_cleanup_time_inner Signed-off-by: Michael Goldenberg <[email protected]>
… keys Signed-off-by: Michael Goldenberg <[email protected]>
…ures rather than web_sys Signed-off-by: Michael Goldenberg <[email protected]>
…nd operating on keys Signed-off-by: Michael Goldenberg <[email protected]>
…edia cache Signed-off-by: Michael Goldenberg <[email protected]>
…t size and access time Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
… keys Signed-off-by: Michael Goldenberg <[email protected]>
…nt with those for other media keys Signed-off-by: Michael Goldenberg <[email protected]>
…_inner Signed-off-by: Michael Goldenberg <[email protected]>
This makes unencrypted content sizes consistent and testable. Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…gnore_media_retention_policy_inner Signed-off-by: Michael Goldenberg <[email protected]>
…tion_policy_inner Signed-off-by: Michael Goldenberg <[email protected]>
…ut into IndexedDB Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
…rather than web_sys Signed-off-by: Michael Goldenberg <[email protected]>
Signed-off-by: Michael Goldenberg <[email protected]>
c971a2c
to
abe244e
Compare
Background
This pull request is part of a series of pull requests to add a full IndexedDB implementation of the
EventCacheStore
andMediaStore
(see #4617, #4996, #5090, #5138, #5226, #5274, #5343, #5384, #5406, #5414, #5497, #5506, #5540, #5574, #5603, #5676, #5682). This particular pull request adds IndexedDB-backed implementations for cleaning expired and over-sized media in IndexedDB viaMediaStore
.Changes
IndexedDB implementations of top-level
MediaStore
functionsThe overarching change is the removal of the nested
MemoryStore
and the addition of IndexedDB-backed implementations for the following functions.MediaStoreInner::clean_inner
MediaStoreInner::last_media_cleanup_time_inner
MediaStoreInner::set_ignore_media_retention_policy
Additionally, the following types, trait implementations, and functions were added to support the functions above.
Types
MediaCleanupTime
- a basic wrapper aroundUnixTime
for representing the last time theMediaStore
was cleaned. This also includes indexed versions of this type optimized for IndexedDB storage.Trait Implementations
Add<Duration>
andSub<Duration>
forUnixTime
Media
Functions
Transaction::get_keys
Transaction::fold_keys_while
IndexeddbMediaStoreTransaction::get_media_cleanup_time
IndexeddbMediaStoreTransaction::put_media_cleanup_time
IndexeddbMediaStoreTransaction::get_media_keys_by_content_size
IndexeddbMediaStoreTransaction::fold_media_keys_by_retention_metadata_while
IndexeddbMediaStoreTransaction::get_cache_size
IndexeddbMediaStoreTransaction::put_media
IndexeddbMediaStoreTransaction::delete_media_by_content_size
IndexeddbMediaStoreTransaction::delete_media_by_content_size_greater_than
IndexeddbMediaStoreTransaction::delete_media_by_last_access
IndexeddbMediaStoreTransaction::delete_media_by_last_access_earlier_than
IndexeddbMediaStoreTransaction::delete_media_by_retention_metadata
IndexeddbMediaStoreTransaction::delete_media_by_retention_metadata_to
Bug Fixes
3a379e061a5d2266ae2be3d5e897d089d0e83df7
- Integration tests forMediaStore
that assure media size constraints are properly implemented expect that content will maintain its size after encoding. For this reason, these tests are recommended to be run against an unencryptedMediaStore
only (see documentation). Previously, unencrypted media contents were Base64 encoded, which increased the size of the contents, causing the tests to fail. Now, an unencryptedMediaStore
does not modify the contents for serialization, but rather stores it as it is provided.377271814a0284183be2c4cdb49c7ef31f189760
-MediaStoreInner::set_media_retention_policy_inner
previously failed to commit the transaction used to set theMediaRetentionPolicy
and so the policy was not properly recorded. The transaction is now being commited.870e1e26718c75e9bb71206fd4085a98557afd14
-IndexeddbMediaStoreTransaction::put_media_if_policy_compliant
previously failed to putMedia
items in IndexedDB when the givenMedia
was set to ignore theMediaRetentionPolicy
. The condition for addingMedia
through this function was modified to correct the error.Caveats
IndexedDB does not seem to allow partial updates to existing objects. So, if one would like to update a single field on an object in IndexedDB, they must do the following.
This can, of course, be very inefficient when an object store's schema contains large fields.
And, unfortunately, this issue affects the existing schema for the
Media
object store.The issue is that the
Media
object store stores metadata and content alongside each other in a single object. So, for instance, to set thelast_access
field of an object in IndexedDB, one has to deserialize and re-serialized the entire content of theMedia
, which might be very large.The following functions are affected by this issue.
MediaStore::replace_media_key
MediaStore::get_media_content
IndexeddbMediaStoreTransaction::access_media_by_id
which sets thelast_access
field of aMedia
objectMediaStore::get_media_content_for_uri
IndexeddbMediaStoreTransaction::access_media_by_id
which sets thelast_access
field of aMedia
objectMediaStore::set_ignore_media_retention_policy
Proposed Solution
I am currently working on a solution to this problem which separates the metadata and content of a
Media
object into two separate object stores. As a result, this would require that retrieving media contents would require two separate queries to IndexedDB, but I think this is preferable to the excessive (de)serialization described above.Future Work
Media
object storeEventCacheStore
andMediaStore
outside of thematrix-sdk-indexeddb
Signed-off-by: Michael Goldenberg [email protected]