Opened 2 months ago
Closed 8 weeks ago
#63004 closed enhancement (fixed)
Allow `count_many_users_posts()` to be short-circuited
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Users | Keywords: | has-patch commit |
Focuses: | administration, performance | Cc: |
Description
For a few reasons, it should be possible to prevent count_many_users_posts()
from performing its query.
The first scenario comes into play when a plugin, such as Co-Authors Plus, removes the default count column. The WP_Users_List_Table
class calls the function regardless of the columns presence, meaning the counts are never used.
Another scenario arises when a user has many, many posts. In one example, a user that is alphabetically first has 65,000 posts, which even on a performance-oriented host can take several seconds to count. Since the counts aren't cached, the delay can become burdensome when navigating through the users list.
Attachments (5)
Change History (18)
#2
@
2 months ago
I'll add the documentation on Monday; I'm kicking myself for omitting it.
I can see adding a default callback to the filter, but given the first scenario I described, I still believe a filter is useful for situations where the counts are never used.
#3
@
2 months ago
Hello @ethitter
I've uploaded the updated patch with additional improvements to the function.
I've updated the following line to better sanitize user IDs:
From:
$userlist = implode( ',', array_map( 'absint', $users ) );
To:
$userlist = implode( ',', wp_parse_id_list( $users ) );
I also added:
$count = array_fill_keys( $userlist, 0 );
This change eliminates the need for an extra foreach
loop.
cc @audrasjb
This ticket was mentioned in PR #8410 on WordPress/wordpress-develop by @audrasjb.
2 months ago
#4
#5
@
2 months ago
Thank you both for your patches. I added a PR based on them to add a missing docblock info and to publicly run GitHub Actions against this changeset.
#6
@
2 months ago
- Keywords needs-refresh added
Please note that there is one PHP Unit Test issue to fix:
1) Tests_User::test_count_many_users_posts array_fill_keys() expects parameter 1 to be array, string given /var/www/src/wp-includes/user.php:683 /var/www/tests/phpunit/tests/user.php:589 phpvfscomposer:///var/www/vendor/phpunit/phpunit/phpunit:97 /var/www/vendor/bin/phpunit:118
This looks like a relevant regression.
#7
@
2 months ago
- Keywords needs-refresh removed
@audrasjb Here is my updated patch and it seems not to create any regression issues.
#9
@
8 weeks ago
- Milestone changed from Awaiting Review to 6.8
- Owner set to jorbin
- Status changed from new to assigned
There isn't much time before beta 1, but I think this is a nice small enhancement that is worth including in 6.8.
@peterwilsoncc commented on PR #8410:
8 weeks ago
#10
@audrasjb I took the liberty of pushing @jigar787's patch (with a minor change) to your branch rather than create another PR for same.
#11
@
8 weeks ago
- Keywords commit added
The tests are passing in the associated pull request based on 63004.5.patch.
I made a minor change and continued to use absint
within the function to sanitize the user IDs to make sure that future changes to wp_parse_ids_list()
don't have an inadvertent effect on escaping.
The unit test for return values and types are passing, as is manual testing.
@audrasjb commented on PR #8410:
8 weeks ago
#12
Great Peter 👍
Hello and thanks for the ticket/patch,
First, the new filter has to be documented using a regular docblock comment.
But I'm also wondering if we should rather use a more generic function to determine whether the user has a lot of posts, quite similarly to
wp_is_large_network()
does.