REST API: Move sideload metadata writing to the finalize endpoint (backport GB #75888)#48
Open
adamsilverstein wants to merge 3 commits into
Open
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Backport of Gutenberg PR #75888. Eliminate the read-modify-write race between concurrent sideloads for the same attachment by no longer writing attachment metadata in the sideload endpoint. Instead, sideload returns lightweight sub-size data (dimensions, filename, filesize) which the client accumulates and passes to the finalize endpoint, which writes all collected sub-sizes in a single metadata update. This matches how core generates sub-sizes (one metadata write after all sizes exist) and replaces the earlier per-attachment locking approach that the merged Gutenberg PR ultimately abandoned.
8245308 to
658fa47
Compare
The three sub-size finalize tests added in this backport used the placeholder ticket 62243 (the original client-side media feature ticket) before a dedicated ticket existed. Trac #65329 now tracks this change, so update those @ticket annotations. Pre-existing finalize tests keep 62243.
This backport changes the scaled-image sideload behavior (sideload now returns sub-size data and metadata is written at finalize), so add a 65329 ticket reference alongside the existing 64737.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Core backport of Gutenberg #75888 — Upload Media: Enable concurrent sideload uploads.
Stacked on top of the client-side-media restore branch (
reintroduce-client-side-media, #11324). Once the restore lands ontrunk, this rebases ontotrunk.Why
Concurrent sideloads for the same attachment each did a read-modify-write of
_wp_attachment_metadata, so parallel requests could overwrite each other's changes. The merged Gutenberg PR explored MySQL advisory locks and transient locks, then settled on removing the shared write entirely.How
sideload_item()no longer writes attachment metadata. It returns lightweight sub-size data (image_size, dimensions,file,mime_type,filesize, andoriginal_imagefor the scaled case). The scaled flow still repoints_wp_attached_file(that is not the contended_wp_attachment_metadata).finalize_item()accepts a newsub_sizesarray param (schema-validated) and applies all collected sub-sizes to the metadata in a singlewp_update_attachment_metadata()before firingwp_generate_attachment_metadata.This matches how core generates sub-sizes (one metadata write after all sizes exist).
Notes
sideloadToServerreturning sub-size data; client-side accumulation passed to finalize) ships via the normal Gutenberg → Core package sync and is not part of this PHP backport.test_sideload_scaled_imageto assert the new response shape + finalize write, and added three finalize tests —test_finalize_writes_regular_sub_sizes,test_finalize_writes_original_metadata(covers theoriginalbranch), andtest_finalize_preserves_image_meta(EXIFimage_metais preserved when finalize adds sub-sizes). Together with the existingtest_finalize_item*tests, all three finalize branches (regular / scaled / original) plus the empty-sub_sizespath are covered. Validated locally withphp -land PHPCS (WordPress-Core); the full PHPUnit suite was not run locally (the wordpress-develop test env is not currently provisioned, and the suite does not run in CI on fork PRs to a non-default base branch).Part of the post-restore client-side-media backport stack.
Trac ticket: https://core.trac.wordpress.org/ticket/65329