﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc	focuses
48451	Regression: wp_update_attachment_metadata filter now fires very often and without complete metadata	ianmjones		"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."	defect (bug)	closed	normal		Media	5.3	normal	worksforme	has-patch needs-testing close		
