Skip to content
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

media: cache media's content after uploading it #4149

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Oct 17, 2024

This adds an optional way to cache a media's content after uploading it successfully. In a followup PR, I'll also add caching of the thumbnail, in a slightly smarter way than we do right now (always return a cache hit independently of the requested thumbnail features).

Part of #1732.

@bnjbvr bnjbvr requested a review from a team as a code owner October 17, 2024 15:04
@bnjbvr bnjbvr requested review from andybalaam and removed request for a team October 17, 2024 15:04
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 69.09091% with 17 lines in your changes missing coverage. Please review.

Project coverage is 84.83%. Comparing base (08152bd) to head (3b9fc3c).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-ui/src/timeline/futures.rs 0.00% 9 Missing ⚠️
crates/matrix-sdk/src/room/mod.rs 80.00% 5 Missing ⚠️
crates/matrix-sdk/src/room/futures.rs 85.71% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4149      +/-   ##
==========================================
- Coverage   84.84%   84.83%   -0.01%     
==========================================
  Files         269      269              
  Lines       28793    28824      +31     
==========================================
+ Hits        24429    24454      +25     
- Misses       4364     4370       +6     

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

Copy link
Member

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

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

Looks good, thanks.

@bnjbvr
Copy link
Member Author

bnjbvr commented Oct 21, 2024

I'm hesitant to merge this, because I think that for the local echo for media upload, we'll need a strategy where we'll first store the media in the cache, with a temporary MXC url, and then after it's been uploaded, replace the underlying temporary MXC url with the one returned from the server. We could use the same strategy here to avoid cloning the data we want to store in the cache, and that will be aligned with the local echo feature.

@bnjbvr bnjbvr force-pushed the bnjbvr/cache-media-after-upload branch 2 times, most recently from 19accca to 722dd22 Compare October 21, 2024 16:12
@bnjbvr bnjbvr requested a review from andybalaam October 21, 2024 16:20
@bnjbvr
Copy link
Member Author

bnjbvr commented Oct 21, 2024

Re-requesting review because of non-trivial changes: I made it so that one can take the bytes by reference instead of by ownership, which required tweaking the SendRequest IntoFuture impl too.

@bnjbvr
Copy link
Member Author

bnjbvr commented Oct 22, 2024

We've discussed this in the Rust chapter, and we're going to keep it super simple (so, remove the last commit), and add caching of thumbnails as is. Drafting.

@bnjbvr bnjbvr marked this pull request as draft October 22, 2024 09:04
Changelog: Uploaded medias can now be cached in multiple
attachment-related methods like `Room::send_attachment`.
@bnjbvr bnjbvr force-pushed the bnjbvr/cache-media-after-upload branch from 22c9590 to daa05ea Compare October 22, 2024 09:40
We can't know which key is going to be used precisely for the thumbnail,
so assume non-animated cropped same-size thumbnail media request.

Changelog: when `SendAttachment::store_in_cache()` is set, the thumbnail
is also cached with a sensible default media request (not animated,
cropped, same dimensions as the uploaded thumbnail).
@bnjbvr bnjbvr force-pushed the bnjbvr/cache-media-after-upload branch from daa05ea to 3b9fc3c Compare October 22, 2024 09:41
@bnjbvr bnjbvr marked this pull request as ready for review October 22, 2024 09:41
@bnjbvr
Copy link
Member Author

bnjbvr commented Oct 22, 2024

Done. Would still appreciate a re-review, since the thumbnail is now being cached too :) Thanks in advance!

Copy link
Member

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

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

Great, thanks

@bnjbvr bnjbvr merged commit 9c03c5d into main Oct 22, 2024
46 of 63 checks passed
@bnjbvr bnjbvr deleted the bnjbvr/cache-media-after-upload branch October 22, 2024 10:06
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