Skip to content

Conversation

@mgoldenberg
Copy link
Contributor

Background

This pull request is part of a series of pull requests to add a full IndexedDB implementation of the EventCacheStore and MediaStore (see #4617, #4996, #5090, #5138, #5226, #5274, #5343, #5384, #5406, #5414, #5497, #5506, #5540, #5574, #5603, #5676). This particular pull request adds IndexedDB-backed implementations for retrieving, storing, replacing, and removing media in IndexedDB via MediaStore.

Changes

IndexedDB implementations of top-level MediaStore functions

The overarching change is the addition of IndexedDB-backed implementations for the following functions.

  • MediaStore::add_media_content
  • MediaStore::replace_media_key
  • MediaStore::get_media_content
  • MediaStore::remove_media_content
  • MediaStore::get_media_content_for_uri
  • MediaStore::remove_media_content_for_uri
  • MediaStoreInner::add_media_content_inner
  • MediaStoreInner::get_media_content_inner
  • MediaStoreInner::get_media_content_for_uri_inner

Additionally, there were a number of changes that needed to be made in order to support the implementations above.

Index media object store by MxcUri rather than MediaSource

Prior to this pull request, the MEDIA object store contained an index that allowed querying by MediaSource; however, what was actually needed was to query by MxcUri given the expectations of the *_for_uri functions above.

So, the MEDIA_SOURCE index has been replaced with a MEDIA_URI index, which allows querying by the MxcUri of the associated media.

Add UnixTime type to better represent Media::last_access

In order to better represent time relative to the Unix Epoch, the following type was added.

pub enum UnixTime {
    BeforeEpoch(Duration),
    AfterEpoch(Duration),
}

This type adds convenience as it is possible to convert a SystemTime to a UnixTime infallibly, given that it supports times before and after the Unix Epoch.

Future Work

  • Add implementation of remaining functions in MediaStore and MediaStoreInner
  • Refactor feature flags
    • The current feature flags are a bit convoluted and could be simplified and made more modular

  • Public API changes documented in changelogs (optional)

Signed-off-by: Michael Goldenberg [email protected]

@codecov
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.37%. Comparing base (62d2d0f) to head (9467fde).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5682   +/-   ##
=======================================
  Coverage   88.37%   88.37%           
=======================================
  Files         355      355           
  Lines       97684    97684           
  Branches    97684    97684           
=======================================
+ Hits        86328    86332    +4     
+ Misses       7287     7283    -4     
  Partials     4069     4069           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 17, 2025

CodSpeed Performance Report

Merging #5682 will not alter performance

Comparing mgoldenberg:indexeddb-media-store-get-add-replace-remove (9467fde) with main (62d2d0f)

Summary

✅ 49 untouched

@mgoldenberg mgoldenberg marked this pull request as ready for review September 17, 2025 13:53
@mgoldenberg mgoldenberg requested a review from a team as a code owner September 17, 2025 13:53
@mgoldenberg mgoldenberg requested review from poljar and removed request for a team September 17, 2025 13:53
Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. Should we have a migration to handle the media_source to media_uri change?

@mgoldenberg
Copy link
Contributor Author

It looks good to me. Should we have a migration to handle the media_source to media_uri change?

I think it probably isn't necessary, given that none of this is exposed publicly outside the crate. I figure once everything is stabilized, we'll make it all public and then future changes will require migrations.

What do you think?

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to me! Thank you very much.

@Hywan Hywan merged commit 1312a27 into matrix-org:main Sep 17, 2025
60 checks passed
@mgoldenberg mgoldenberg deleted the indexeddb-media-store-get-add-replace-remove branch September 17, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants