Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.7.0 introduced a slow query from avatar alt text, Add option to filter avatar alt #1923

Closed
c0ntax opened this issue Oct 22, 2024 · 2 comments · Fixed by #1961
Closed

4.7.0 introduced a slow query from avatar alt text, Add option to filter avatar alt #1923

c0ntax opened this issue Oct 22, 2024 · 2 comments · Fixed by #1961

Comments

@c0ntax
Copy link
Contributor

c0ntax commented Oct 22, 2024

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 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

  1. Introducing caching
  2. Add a filter get_custom_avatar filter so that users's can introduce their own caching or do things differently
  3. Roll back the code to 4.6.x?

Steps to Reproduce (for bugs)

  1. Have a site with lots of posts and lots of metadata per post
  2. Render an author with a custom avatar on a page
  3. 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)
@ojopaul ojopaul changed the title 4.7.0 introduced a slow query 4.7.0 introduced a slow query from avatar alt text, Add option to filter avatar alt Dec 16, 2024
ojopaul added a commit that referenced this issue Dec 16, 2024
…-slow-query-from-avatar-alt-text-Add-option-to-filter-avatar-alt

fix/#1923-470-introduced-a-slow-query-from-avatar-alt-text-Add-option-to-filter-avatar-alt
@ojopaul
Copy link
Collaborator

ojopaul commented Dec 16, 2024

Hi @c0ntax, Thanks for your report.

Right now, we're using attachment_url_to_postid to get avatar post id so we can retrieve avatar alt text from their post as requested by users but I agree with you such function should be filterable in case of large site users like yours.

So, we introduced a filter in the coming release with information here.

You can use the filter and simply return "Avatar" or empty string "" or any non null value to prevent the function from querying for avatar alt.

Thanks

ojopaul added a commit that referenced this issue Dec 16, 2024
…-slow-query-from-avatar-alt-text-Add-option-to-filter-avatar-alt

Fix null check
@c0ntax
Copy link
Contributor Author

c0ntax commented Dec 17, 2024

@ojopaul you sir, are a star! Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants