When displaying a post with an author's custom avatar, the code to generate the page should be performant
Current Behavior
get_custom_avatar() now uses attachment_url_to_postid(). This function searches the postmeta table by both meta_key and meta_value. Meta_value() cannot be indexed because it's a longtext so you end up with an inefficient query that can run on a page multiple times. It was adding anywhere between 0.8s and 1.5s to every page that displayed an author on my site.
Possible Solution
Introducing caching
Add a filter get_custom_avatar filter so that users's can introduce their own caching or do things differently
Roll back the code to 4.6.x?
Steps to Reproduce (for bugs)
Have a site with lots of posts and lots of metadata per post
Render an author with a custom avatar on a page
Look the Query Monitor tool bar light up
Context
I just want an author with a custom avatar on a page.
Your Environment
Version used: 4.7.2
Browser Name and version: N/A
Operating System and version (desktop or mobile): Ubuntu 22.04.1-Ubuntu (Kernel 6.8.0-47-generic)
Expected Behavior
When displaying a post with an author's custom avatar, the code to generate the page should be performant
Current Behavior
get_custom_avatar()
now usesattachment_url_to_postid()
. This function searches the postmeta table by both meta_key and meta_value. Meta_value() cannot be indexed because it's a longtext so you end up with an inefficient query that can run on a page multiple times. It was adding anywhere between 0.8s and 1.5s to every page that displayed an author on my site.Possible Solution
Steps to Reproduce (for bugs)
Context
I just want an author with a custom avatar on a page.
Your Environment