mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@53011 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -100,21 +100,6 @@ function get_active_blog_for_user( $user_id ) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of active users in your installation.
|
||||
*
|
||||
* The count is cached and updated twice daily. This is not a live count.
|
||||
*
|
||||
* @since MU (3.0.0)
|
||||
* @since 4.8.0 The `$network_id` parameter has been added.
|
||||
*
|
||||
* @param int|null $network_id ID of the network. Default is the current network.
|
||||
* @return int Number of active users on the network.
|
||||
*/
|
||||
function get_user_count( $network_id = null ) {
|
||||
return get_network_option( $network_id, 'user_count' );
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of active sites on your installation.
|
||||
*
|
||||
@@ -2611,16 +2596,12 @@ function wp_update_network_site_counts( $network_id = null ) {
|
||||
*
|
||||
* @since 3.7.0
|
||||
* @since 4.8.0 The `$network_id` parameter has been added.
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
* @since 6.0.0 This function is now a wrapper for wp_update_user_counts().
|
||||
*
|
||||
* @param int|null $network_id ID of the network. Default is the current network.
|
||||
*/
|
||||
function wp_update_network_user_counts( $network_id = null ) {
|
||||
global $wpdb;
|
||||
|
||||
$count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
|
||||
update_network_option( $network_id, 'user_count', $count );
|
||||
wp_update_user_counts( $network_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2754,6 +2735,9 @@ function wp_is_large_network( $using = 'sites', $network_id = null ) {
|
||||
|
||||
if ( 'users' === $using ) {
|
||||
$count = get_user_count( $network_id );
|
||||
|
||||
$is_large_network = wp_is_large_user_count( $network_id );
|
||||
|
||||
/**
|
||||
* Filters whether the network is considered large.
|
||||
*
|
||||
@@ -2765,7 +2749,7 @@ function wp_is_large_network( $using = 'sites', $network_id = null ) {
|
||||
* @param int $count The count of items for the component.
|
||||
* @param int $network_id The ID of the network being checked.
|
||||
*/
|
||||
return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id );
|
||||
return apply_filters( 'wp_is_large_network', $is_large_network, 'users', $count, $network_id );
|
||||
}
|
||||
|
||||
$count = get_blog_count( $network_id );
|
||||
|
||||
Reference in New Issue
Block a user