REST API: Move sideload metadata writing to the finalize endpoint (backport GB #75888)#12002
REST API: Move sideload metadata writing to the finalize endpoint (backport GB #75888)#12002adamsilverstein wants to merge 4 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.
|
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. |
|
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. |
Moving sideload metadata writing to the finalize endpoint adds a sub_sizes argument to that endpoint's schema. Regenerate tests/qunit/fixtures/wp-api-generated.js so the "fixtures are up to date" CI guard (git diff --exit-code) passes.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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