Make WordPress Core

03/29/2022 12:41:00 PM (18 months ago)

Users: Introduce the concept of a large site to single site installations.

Currently in WordPress multisite there is a concept of large networks. The function wp_is_large_network is used to determine if a network has a large number of sites or users. If a network is marked as large, then
expensive queries to calculate user counts are not run on page load but deferred to scheduled events. However there are a number of places in a single site installation where this functionality would also be useful, as
expensive calls to count users and roles can make screens in the admin extremely slow.

In this change, the get_user_count function and related functionality around it is ported to be available in a single site context. This means that expensive calls to the count_users function are replaced with
calls to get_user_count. This change also includes a new function called wp_is_large_user_count and a filter of the same name, to mark if a site is large.

Props johnbillion, Spacedmonkey, Mista-Flo, lumpysimon, tharsheblows, obenland, miss_jwo, jrchamp, flixos90, macbookandrew, pento, desrosj, johnjamesjacoby, jb510, davidbaumwald, costdev.
Fixes #38741.

1 edited


  • trunk/src/wp-includes/ms-default-filters.php

    r52207 r53011  
    8585add_action( 'admin_init', 'wp_schedule_update_network_counts' );
    8686add_action( 'update_network_counts', 'wp_update_network_counts', 10, 0 );
    87 foreach ( array( 'user_register', 'deleted_user', 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) {
     87foreach ( array( 'wpmu_new_user', 'make_spam_user', 'make_ham_user' ) as $action ) {
    8888    add_action( $action, 'wp_maybe_update_network_user_counts', 10, 0 );
     91// These counts are handled by wp_update_network_counts() on Multisite:
     92remove_action( 'admin_init', 'wp_schedule_update_user_counts' );
     93remove_action( 'wp_update_user_counts', 'wp_schedule_update_user_counts' );
    9095foreach ( array( 'make_spam_blog', 'make_ham_blog', 'archive_blog', 'unarchive_blog', 'make_delete_blog', 'make_undelete_blog' ) as $action ) {
    9196    add_action( $action, 'wp_maybe_update_network_site_counts', 10, 0 );
Note: See TracChangeset for help on using the changeset viewer.