#40490 closed enhancement (fixed)
Prime post cache in `wp_make_content_images_responsive()`
Reported by: | dlh | Owned by: | joemcgill |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description
[35412] updated wp_make_content_images_responsive()
so that it "warmed the cache" with update_meta_cache()
before calling get_post_meta()
.
[38296] replaced get_post_meta()
with wp_get_attachment_metadata()
, but because the latter function calls get_post()
, it can still cause a database query for each attachment that isn't in the cache.
The attached patch would have wp_make_content_images_responsive()
use _prime_post_caches()
again to avoid the individual queries.
Attachments (2)
Change History (8)
This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.
7 years ago
#4
@
7 years ago
This is a great catch, @dlh.
Originally, when we implemented wp_make_content_images_responsive()
we intentionally decided to only query the post meta using get_post_meta()
as to avoid the extra Post queries, which is why update_meta_cache()
was used in [35412]. However, it makes sense that someone filtering the values of wp_get_attachment_metadata()
would want consistency here as well, so switching back to _prime_post_caches()
is better here and avoids a bunch on unnecessary queries.
We may also want to consider ways we can avoid the get_post()
check inside of wp_get_attachment_metadata()
since those queries are often unnecessary when only metadata is needed.
In the mean time, this patch is a good improvement.
Refining docs