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

fix(send_queue): Use MediaFormat::File when caching attachment thumbnail #4400

Merged
merged 3 commits into from
Dec 11, 2024

Conversation

zecakeh
Copy link
Collaborator

@zecakeh zecakeh commented Dec 10, 2024

Fix extracted from #4329.

The MediaFormat reflects only the request that would be made to the homeserver. There is no link between the format of the files stored in the media cache and their purpose in an event. MediaFormat::Thumbnail means that we request a server-generated thumbnail of a file in the media repository. Since the thumbnail is its own file in the media repository, it makes more sense to use MediaFormat::File. See #4329 (comment) for even more details why this change makes sense.

The fix was simplified a lot here. Instead of requiring a migration, we just minimize the changes in the format of the send queue request in the state store and keep handling the previous case.

This also documents the caching of the media when calling send_attachment.

The `MediaFormat` reflects only the request that would be made to the homeserver.
There is no link between the format of the files stored in the media cache and their purpose in an event.

`MediaFormat::Tumbnail` means that we request a server-generated thumbnail of a file in the media repository.

Since the thumbnail is its own file in the media repository, it makes more sense to use `MediaFormat::File`.

Signed-off-by: Kévin Commaille <[email protected]>
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.22%. Comparing base (cf178d6) to head (1c106d2).
Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/send_queue/upload.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4400      +/-   ##
==========================================
- Coverage   85.25%   85.22%   -0.03%     
==========================================
  Files         282      282              
  Lines       31065    31064       -1     
==========================================
- Hits        26483    26475       -8     
- Misses       4582     4589       +7     

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

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

Thank you, nice serde trickery!

let from_req =
Media::make_local_thumbnail_media_request(&info.txn, info.height, info.width);
// Previously the media request used `MediaFormat::Thumbnail`. Handle this case
// for send queue requests that were in the state store before the change.
Copy link
Member

Choose a reason for hiding this comment

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

state store? or cache store?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is about DependentQueuedRequestKind, so the state store, right?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right 🤦

Comment on lines +101 to +104
/// The attachment and its optional thumbnail are stored in the media cache
/// and can be retrieved at any time, by calling
/// [`Media::get_media_content()`] with the `MediaSource` that can be found
/// in the local or remote echo, and using a `MediaFormat::File`.
Copy link
Member

Choose a reason for hiding this comment

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

<3

@bnjbvr bnjbvr merged commit a562f73 into matrix-org:main Dec 11, 2024
40 checks passed
@zecakeh zecakeh deleted the thumbnail-as-file-request branch December 11, 2024 09:46
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