Skip to content

refactor(send_queue): generalize SentRequestKey::Media and DependentQueuedRequestKind::UploadFileWithThumbnail to prepare for MSC4274 gallery uploads #4897

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

Merged
merged 19 commits into from
Apr 24, 2025

Conversation

Johennes
Copy link
Contributor

@Johennes Johennes commented Apr 7, 2025

This was broken out of #4838 and is a preliminary step towards implementing MSC4274. SentRequestKey::Media and DependentQueuedRequestKind::UploadFileWithThumbnail are generalized to allow chaining dependent media uploads and accumulating sent media sources.

  • Public API changes documented in changelogs (optional)

…ueuedRequestKind::UploadFileWithThumbnail to prepare for MSC4274 gallery uploads

Signed-off-by: Johannes Marbach <[email protected]>
Copy link

codecov bot commented Apr 7, 2025

Codecov Report

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

Project coverage is 85.70%. Comparing base (f7f07e7) to head (773d928).
Report is 171 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    #4897   +/-   ##
=======================================
  Coverage   85.69%   85.70%           
=======================================
  Files         309      309           
  Lines       35398    35400    +2     
=======================================
+ Hits        30334    30338    +4     
+ Misses       5064     5062    -2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Johennes Johennes marked this pull request as ready for review April 7, 2025 18:28
@Johennes Johennes requested a review from a team as a code owner April 7, 2025 18:28
@Johennes Johennes requested review from Hywan and removed request for a team April 7, 2025 18:28
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.

Thanks for the patch.
I believe it would be lovely to add a couple of tests just to ensure the accumulated field correctly accumulates the media info. Is it doable?

@Johennes
Copy link
Contributor Author

Johennes commented Apr 8, 2025

I believe it would be lovely to add a couple of tests just to ensure the accumulated field correctly accumulates the media info. Is it doable?

It is slightly tricky because I think currently it can only be tested indirectly through the final event that is being sent. For galleries the code to send the event is still missing, however. I was planning to add it with a separate PR, including tests. I realize this isn't ideal but I'm not sure how to best test it in this PR here. 😕

@Johennes Johennes requested a review from Hywan April 8, 2025 09:34
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 makes sense to me, thank you. @bnjbvr would you like to take a look too?

@bnjbvr
Copy link
Member

bnjbvr commented Apr 16, 2025

Yep, thanks for the ping.

@bnjbvr bnjbvr self-requested a review April 16, 2025 08:57
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.

Thanks! There might be a subtle breaking data format change here, so requesting changes to double-check this with a test, at least.

Comment on lines +339 to +343
/// Accumulated list of infos for previously uploaded files and thumbnails
/// if used during a gallery transaction. Otherwise empty.
#[cfg(feature = "unstable-msc4274")]
#[serde(default)]
pub accumulated: Vec<AccumulatedSentMediaInfo>,
Copy link
Member

Choose a reason for hiding this comment

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

There might be a different possible data scheme here, if I understand correctly:

  • SentMediaInfo contains only the vec of AccumulatedSentMediaInfo (since a vec can hold the pair for the media, when there's only a single one and no gallery)
  • AccumulatedSentMediaInfo (maybe rename SingleSentMediaInfo?) can keep on holding its current fields.

Again, I see this struct SentMediaInfo is also marked as Serialized/Deserialize, so maybe what I'm suggesting implies having to a data migration 🥴.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think technically this would work, yes. I didn't go for it originally because I wanted to minimize breaking changes and because it felt slightly cleaner to have accumulated only contain the requests that are actually finished. This way, we only push to accumulated. If we do it the other way around, we'll need to push or modify the last item depending on what the request is for. Did you have specific advantages of using this variant in mind?

Copy link
Member

Choose a reason for hiding this comment

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

The only advantage is technical, in that it avoids containing what's effectively another flattened AccumulatedSentMediaInfo next to the accumulated vector, and also reduces the number of concepts.

I'm a bit torn, because this is likely a non-trivial change, but on the other hand that might be a nice simplification. Maybe that could be attempted as a follow-up, and we could open an issue to not forget about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see the oddness. Sounds good on the issue. I have opened: #4969

@Johennes Johennes requested a review from bnjbvr April 22, 2025 20:37
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.

Looks good to me, thanks. Approving so that we can merge this as soon as my review comments have been addressed. Any chance we can also include some unit tests relevant to the changes here, or is that not worth it?

Comment on lines +339 to +343
/// Accumulated list of infos for previously uploaded files and thumbnails
/// if used during a gallery transaction. Otherwise empty.
#[cfg(feature = "unstable-msc4274")]
#[serde(default)]
pub accumulated: Vec<AccumulatedSentMediaInfo>,
Copy link
Member

Choose a reason for hiding this comment

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

The only advantage is technical, in that it avoids containing what's effectively another flattened AccumulatedSentMediaInfo next to the accumulated vector, and also reduces the number of concepts.

I'm a bit torn, because this is likely a non-trivial change, but on the other hand that might be a nice simplification. Maybe that could be attempted as a follow-up, and we could open an issue to not forget about it?

Comment on lines +382 to +386
// If the parent request was a thumbnail upload, don't add it to the list of
// accumulated medias yet because its dependent file upload is still
// pending. If the parent request was a file upload, we know that both
// the file and its thumbnail (if any) have finished uploading and we
// can add them to the accumulated sent media.
Copy link
Member

Choose a reason for hiding this comment

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

Super nice comment, thanks!

Co-authored-by: Benjamin Bouvier <[email protected]>
Signed-off-by: Johannes Marbach <[email protected]>
@bnjbvr bnjbvr enabled auto-merge (squash) April 24, 2025 09:38
@bnjbvr bnjbvr merged commit 1554e05 into matrix-org:main Apr 24, 2025
43 checks passed
@Johennes
Copy link
Contributor Author

Thanks for the merge! Re the unit tests, I just wanted to say that it's a bit tricky on this PR because most of the changes are just routing new fields through existing APIs but nothing really uses these new fields yet. Therefore, I was planning to add tests in future PRs when the accumulation is actually being used by galleries.

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.

3 participants