Skip to content

Conversation

@spacedmonkey
Copy link
Member

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.

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.

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.
@github-actions
Copy link

github-actions bot commented Feb 26, 2025

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props spacedmonkey, westonruter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@westonruter
Copy link
Member

@spacedmonkey I'm trying to follow your testing instructions, but I'm having trouble.

  1. I've activated the Twenty Nineteen theme.
  2. I've created two pages: One without an Author block and another with an Author block.
  3. I only have Query Monitor active.
  4. I'm viewing Page template.

Trunk

Without Author Block With the Author Block
image image

PR

Without Author Block With the Author Block
image image

👉🏻 In all cases, I see the same count of 21 queries. What am I missing?

@spacedmonkey
Copy link
Member Author

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

Trunk PR
Screenshot 2025-10-08 at 21 20 1873 queries Screenshot 2025-10-08 at 21 20 0572 queries
Screenshot 2025-10-08 at 21 23 57 67 queries Screenshot 2025-10-08 at 21 22 33 66 queries

I am seeing one less query on a number of different types of page load.

The query I am no longer seeing this one.
Screenshot 2025-10-08 at 21 28 25

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.
Copy link
Member

@westonruter westonruter left a 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);

@spacedmonkey
Copy link
Member Author

Committed in [60989]

@spacedmonkey spacedmonkey deleted the fix/lazy-loading-user-meta branch October 20, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants