-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add lazy-loading support for user metadata. #8411
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
Add lazy-loading support for user metadata. #8411
Conversation
Introduce the `wp_lazyload_user_meta` function to queue user metadata for lazy-loading, optimizing user meta retrieval. Update related functions, tests, and metadata lazyloader to support this functionality, ensuring improved performance and consistency.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Co-authored-by: Weston Ruter <westonruter@gmail.com>
|
@spacedmonkey I'm trying to follow your testing instructions, but I'm having trouble.
Trunk
PR
👉🏻 In all cases, I see the same count of 21 queries. What am I missing? |
|
@westonruter Sorry for the confused but to see the benefit, this must first be committed. Now it is committed and this PR rebased, I am seeing the benefit.
I am seeing one less query on a number of different types of page load. The query I am no longer seeing this one. This means 28 less rows of user meta loaded. For sites with lots of user meta or multisite, this could be a massive win. |
Enhance tests to verify behavior when author metadata is explicitly loaded using `get_the_author_meta`, ensuring user IDs are properly primed.
Add new tests to handle various scenarios, including users not in the lazy load queue. Update existing tests to reduce created user count and include cache clearing, ensuring more robust and efficient validation of lazy-loading behavior.
westonruter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was finally able to replicate the reduction in queries on the single template, but only after I set the First Name, Last Name, and Display Name for the author of the post I was viewing:
--- before.sql 2025-10-09 18:21:53
+++ after.sql 2025-10-09 18:20:55
@@ -11,7 +11,6 @@
SELECT wp_posts.* FROM wp_posts WHERE ID IN (518,288);
SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (518,288) ORDER BY meta_id ASC;
SELECT DISTINCT t.term_id, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('wp_theme') AND tr.object_id IN (518, 288) ORDER BY t.name ASC;
-SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE user_id IN (1) ORDER BY umeta_id ASC;
SELECT * FROM wp_users WHERE ID IN (1);
SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND wp_posts.post_name IN ('header') AND ( wp_term_relationships.term_taxonomy_id IN (2) ) AND wp_posts.post_type = 'wp_template_part' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 1;
SELECT wp_posts.* FROM wp_posts WHERE ID IN (315);|
Committed in [60989] |









Introduce the
wp_lazyload_user_metafunction to queue user metadata for lazy-loading, optimizing user meta retrieval. Update related functions, tests, and metadata lazyloader to support this functionality, ensuring improved performance and consistency.Trac ticket: https://core.trac.wordpress.org/ticket/63021
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.