Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit users query in search_authors #872

Merged
merged 1 commit into from
Oct 21, 2022
Merged

Conversation

leogermani
Copy link
Contributor

When we call search_authors, CAP is also taking the opportunity to update the user terms.

In order to do that, it queries for all users in the database:

$args = array(

When a site has too many users, this can be a problem, especially because this can be called with an empty search and would try to load all users of the site at once.

Previous work

I saw that you tried to fix this issue 4 years ago, but it got reverted.

This fix

This is an attempt to have a quick fix for this, without trying to replicate all the logic in the PR merged 4 years ago.

I saw that in that attempt, they were filtering out users who did not have the capability to edit posts. See:

https://github.com/Automattic/Co-Authors-Plus/pull/544/files#diff-a3596cc30542e2cf428e6b5c295e6d757efda1539e9b3d2b8aaea5e818e3753dR45

Also, in our current code, we never return users who don't have this capability:

} elseif ( 'wpuser' === $found_user->type && false === $found_user->has_cap( apply_filters( 'coauthors_edit_author_cap', 'edit_posts' ) ) ) {

So what I propose in this PR is just to run this filter earlier, and only fix terms for users who have this capability.

Can someone have a look at it?

Known issue: This will filter out users who have rights to edit other post types, but not posts. But this is already a limitation of the plugin. If we had a post_type in that context we could check for the right cap.

Question: In the comments I see that this is addressing something for people who were running CAP < 2.7. If that's only for this purpose and is not required for newer versions, do you think it has been there for long enough and this could be removed altogether?

@lkraav
Copy link

lkraav commented Sep 28, 2022

I can confirm, on our userbase of 50k, co-authors-plus request are timing out on post editor screens exactly as described.

@rebeccahum rebeccahum merged commit 29de0fe into master Oct 21, 2022
@rebeccahum rebeccahum deleted the update/limit-user-query branch October 21, 2022 17:41
@leogermani leogermani restored the update/limit-user-query branch October 21, 2022 19:35
@GaryJones GaryJones deleted the update/limit-user-query branch July 24, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants