Make WordPress Core


Ignore:
Timestamp:
04/30/2017 01:02:50 PM (8 years ago)
Author:
johnbillion
Message:

Users: Ensure user counts remain accurate if users are added to or removed from the users table without corresponding usermeta entries being added or removed.

This has a slight performance impact on sites with a large number of users when the time strategy is used for counting users. Hopefully this impact will be negated by enhancements proposed in #38741.

Props psoluch, dots, boonebgorges, ptbello, tharsheblows

Fixes #29785

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/countUsers.php

    r40543 r40560  
    170170        ), $count['avail_roles'] );
    171171
     172    }
     173
     174    /**
     175     * @ticket 29785
     176     *
     177     * @dataProvider data_count_users_strategies
     178     */
     179    public function test_count_users_should_not_count_users_who_are_not_in_posts_table( $strategy ) {
     180        global $wpdb;
     181
     182        // Get a 'before' count for comparison.
     183        $count = count_users( $strategy );
     184
     185        $u = self::factory()->user->create( array(
     186            'role' => 'editor',
     187        ) );
     188
     189        // Manually delete the user, but leave the capabilities usermeta.
     190        $wpdb->delete( $wpdb->users, array(
     191            'ID' => $u,
     192        ) );
     193
     194        $count2 = count_users( $strategy );
     195
     196        $this->assertEqualSets( $count, $count2 );
    172197    }
    173198
Note: See TracChangeset for help on using the changeset viewer.