Make WordPress Core


Ignore:
Timestamp:
04/18/2023 11:48:46 AM (15 months ago)
Author:
spacedmonkey
Message:

Users: Cache database queries within WP_User_Query class.

Cache the results of database queries within WP_User_Query class. Only cache queries that are requesting 3 or less fields so that caches are not storing full user objects. Cache results are stored in a new global cache group named users-queries. Add a new parameter to WP_User_Query called cache_results to allow developers to opt out of a receiving cached results. cache_results parameter defaults to true. Also add a new helper function called wp_cache_set_users_last_changed, similar to wp_cache_set_posts_last_changed that incroments last changed value in cache group users. Ensure that wp_cache_set_users_last_changed is called whenever user / user meta is modified for proper cache invalidation.

Props johnjamesjacoby, spacedmonkey, westi, dd32, strategio, srikanthmeenakshi, OllieJones, khoipro, rjasdfiii, flixos90, mukesh27, peterwilsoncc.
Fixes #40613.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r55620 r55657  
    115115add_action( 'updated_post_meta', 'wp_cache_set_posts_last_changed' );
    116116add_action( 'deleted_post_meta', 'wp_cache_set_posts_last_changed' );
     117
     118// User meta.
     119add_action( 'added_user_meta', 'wp_cache_set_users_last_changed' );
     120add_action( 'updated_user_meta', 'wp_cache_set_users_last_changed' );
     121add_action( 'deleted_user_meta', 'wp_cache_set_users_last_changed' );
     122add_action( 'add_user_role', 'wp_cache_set_users_last_changed' );
     123add_action( 'set_user_role', 'wp_cache_set_users_last_changed' );
     124add_action( 'remove_user_role', 'wp_cache_set_users_last_changed' );
    117125
    118126// Term meta.
Note: See TracChangeset for help on using the changeset viewer.