REST API: Move sideload metadata writing to the finalize endpoint (backport GB #75888)#12002
Open
adamsilverstein wants to merge 3 commits into
Open
REST API: Move sideload metadata writing to the finalize endpoint (backport GB #75888)#12002adamsilverstein wants to merge 3 commits into
adamsilverstein wants to merge 3 commits into
Conversation
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.
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
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Member
|
This also seems to have much of the same code as #12003, which I've reviewed in depth, so I guess that should be committed first before proceeding here. |
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.
Part of the post-restore client-side-media backport stack (see #11324).
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).Trac ticket: https://core.trac.wordpress.org/ticket/65329