Make WordPress Core

Opened 6 months ago

Last modified 3 weeks ago

#58001 new enhancement

Lazy load user capabilities in WP_User object

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Users Keywords: has-patch has-unit-tests
Focuses: multisite, performance Cc:


WP_User object are used throughout WordPress and are loaded on the front end in WP_Query. This means creating a WP_User object and this calls for_site method. This calls to user meta and setups capability data. For a page with multiple users on it, this setup of users, can be done multiple times. Loading user meta for all the users, can be a problem, as this can be a lot of rows of data. For example, this can result in 150 rows being loaded from the database for just 10 users. For multisites or sites that have plugins that are heavy users of user meta, that number can get much higher.

User meta is only loaded along with users, as it is needed for capability data. To improve performance, find someway to lazy load the capability only when they are used and also lazily load user meta at the same time.

Change History (2)

This ticket was mentioned in PR #5098 on WordPress/wordpress-develop by @spacedmonkey.

3 weeks ago

  • Keywords has-patch has-unit-tests added

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.

3 weeks ago

Note: See TracTickets for help on using tickets.