mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Users: Introduce the concept of a large site in order to speed up the Users screen when there are many users.
Calling the `count_users()` function is expensive, regardless of the counting strategy that's used, and it gets slower the more users there are on a site. In order to speed up the Users screen in the admin area, calling `count_users()` can be avoided entirely while still displaying the total count for users. This introduces some new functions: * `wp_is_large_user_count()` * `wp_get_active_user_count()` * `wp_update_active_user_count()` A corresponding `wp_is_large_user_count` filter is also introduced. Props tharsheblows, johnbillion Fixes #38741 git-svn-id: https://develop.svn.wordpress.org/trunk@41613 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1160,4 +1160,58 @@ class Tests_Functions extends WP_UnitTestCase {
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38741
|
||||
*/
|
||||
public function test_wp_get_active_user_count() {
|
||||
$user_count = wp_get_active_user_count();
|
||||
$this->assertSame( $user_count, 1 );
|
||||
|
||||
// make twenty additional users to make 21 users
|
||||
self::factory()->user->create_many( 20 );
|
||||
|
||||
$user_count = wp_get_active_user_count();
|
||||
$this->assertSame( $user_count, 21 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38741
|
||||
*/
|
||||
public function test_wp_get_active_user_count_caching() {
|
||||
global $wpdb;
|
||||
|
||||
// Ensure we start with 1 user
|
||||
$user_count = wp_get_active_user_count();
|
||||
$this->assertSame( $user_count, 1 );
|
||||
|
||||
self::factory()->user->create();
|
||||
|
||||
delete_option( 'active_user_count' );
|
||||
|
||||
// Ensure we now have 2 users
|
||||
$user_count = wp_get_active_user_count();
|
||||
$this->assertSame( $user_count, 2 );
|
||||
|
||||
$queries = $wpdb->num_queries;
|
||||
|
||||
// Ensure that caching inside wp_get_active_user_count() works as expected
|
||||
$user_count = wp_get_active_user_count();
|
||||
$this->assertSame( $user_count, 2 );
|
||||
$this->assertSame( $queries, $wpdb->num_queries );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38741
|
||||
*/
|
||||
public function test_wp_is_large_user_count() {
|
||||
// set the 'active_user_count' value to over 10000 to emulate a large site
|
||||
update_option( 'active_user_count', 10001 );
|
||||
$user_count = wp_get_active_user_count();
|
||||
$this->assertSame( $user_count, 10001 );
|
||||
$this->assertTrue( wp_is_large_user_count() );
|
||||
|
||||
delete_option( 'active_user_count' );
|
||||
$this->assertFalse( wp_is_large_user_count() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user