You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
REST API: Move sideload metadata writing to the finalize endpoint
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.
Copy file name to clipboardExpand all lines: tests/phpunit/tests/rest-api/rest-attachments-controller.php
+71-4Lines changed: 71 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -3275,16 +3275,32 @@ public function test_sideload_scaled_image() {
3275
3275
3276
3276
$this->assertSame( 200, $response->get_status(), 'Sideloading scaled image should succeed.' );
3277
3277
3278
+
// The sideload endpoint returns lightweight sub-size data; the metadata
3279
+
// is written later by the finalize endpoint.
3280
+
$sub_size = $response->get_data();
3281
+
$this->assertSame( 'scaled', $sub_size['image_size'], 'Response should echo the image_size.' );
3282
+
$this->assertSame( wp_basename( $original_file ), $sub_size['original_image'], 'Response original_image should be the basename of the original attached file.' );
3283
+
$this->assertGreaterThan( 0, $sub_size['width'], 'Response width should be positive.' );
3284
+
$this->assertGreaterThan( 0, $sub_size['height'], 'Response height should be positive.' );
3285
+
$this->assertGreaterThan( 0, $sub_size['filesize'], 'Response filesize should be positive.' );
3286
+
$this->assertStringContainsString( 'scaled', $sub_size['file'], 'Response file should reference the scaled version.' );
3287
+
3288
+
// The attached file is still repointed to the scaled version during sideload.
// The original file should now be recorded as original_image.
3281
3301
$this->assertArrayHasKey( 'original_image', $metadata, 'Metadata should contain original_image.' );
3282
3302
$this->assertSame( wp_basename( $original_file ), $metadata['original_image'], 'original_image should be the basename of the original attached file.' );
3283
3303
3284
-
// The attached file should now point to the scaled version.
0 commit comments