[wp-trac] [WordPress Trac] #48451: Regression: wp_update_attachment_metadata filter now fires very often and without compete metadata

WordPress Trac noreply at wordpress.org
Mon Oct 28 20:14:17 UTC 2019


#48451: Regression: wp_update_attachment_metadata filter now fires very often and
without compete metadata
--------------------------+-----------------------------
 Reporter:  ianmjones     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 WP5.3 has changed how often the `wp_update_attachment_metadata` filter is
 fired when an image is uploaded to the Media Library.

 It fires initially with just the `full` (and potentially `original_image`)
 details but no `sizes`, and then again as each image sub-size is generated
 and added to the `sizes` array.

 With `wp_update_attachment_metadata` now firing a minimum of 5 times (10
 for "large" files) instead of once, I predict quite a resource hit from
 plugins processing the filter. There's plenty of image related plugins
 that hang off that filter to trigger optimizations and other media related
 processes assuming that the upload is now complete and thumbnails
 available.

 We regularly see customers with 25-40 or more registered image sizes,
 that's going to mean rather a lot of database calls to update the metadata
 as each sub-size is generated, followed by plugins processing the image(s)
 each time.

 Maybe the solution is for `wp_update_attachment_metadata()` to gain an
 `$unfiltered` param that is set to true during initial upload and sub-size
 generation, with a final call to the function without $unfiltered when
 done and dusted?

 A common pattern throughout WP5.2 (and still in WP5.3) is as follows...

 `wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id,
 $file ) );`

 Such as in `\media_handle_upload()` and friends.

 So that's why a lot of plugins wait for the complete metadata to be
 generated (`wp_generate_attachment_metadata`) and then saved
 (`wp_update_attachment_metadata`) before handling the new upload.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48451>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list