Automattic / Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
https://wordpress.org/plugins/co-authors-plus/
GNU General Public License v2.0
291 stars 206 forks source link

Ajax suggest metabox shows 0 results frequent #235

Open dpacmittal opened 9 years ago

dpacmittal commented 9 years ago

In search_authors() function:

$args = array(
    'search' => $search,
    'get' => 'all',
    'number' => 10,
);
$args = apply_filters( 'coauthors_search_authors_get_terms_args', $args );
add_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) );
$found_terms = get_terms( $this->coauthor_taxonomy, $args );
remove_filter( 'terms_clauses', array( $this, 'filter_terms_clauses' ) );

if ( empty( $found_terms ) )
    return array();
// Get the co-author objects
$found_users = array();
foreach( $found_terms as $found_term ) {
    $found_user = $this->get_coauthor_by( 'user_nicename', $found_term->slug );
    if ( !empty( $found_user ) )
        $found_users[$found_user->user_login] = $found_user;
}

This searches for only 10 terms. The array is then filtered using get_coauthor_by function. Sometimes this leaves the resultset to be empty, when it shouldn't be (because we only looked for 10 terms in the first place).

We should increase the 'number' to more sensible value, or find a better way (using SQL?) to get coauthors from the terms. Another solution would be to loop it until we have atleast X number of results.

rohitkeshwani07 commented 7 years ago

I am facing the same issue. Any update on this?

TheCrowned commented 6 years ago

So, as of now a coauthor selected by get_terms() can be dropped if

The first case can be filtered out in get_terms() itself with the exclude argument, so that' good. The second case can't really be filtered out a priori, as far as I know.

One solution would be to select maybe 20 coauthors already excluding the $ignored ones, and then filtering for permissions. At this point I expect the resulting set to contain something, at least, but possibly more than 10 coauthors. We may then return at most 10 of them. What do you guys think @philipjohn ?

philipjohn commented 6 years ago

Even with a limit of 20 we're likely to hit the same issue on a site with a large number of contributors.

What's stopping us from bumping the limit up to something like 100? What effect would that have on the query - would it make it too expensive? If so, could we be clever with caching to limit the impact?

TheCrowned commented 6 years ago

With #544, users who do not have the capability to be added as coauthors will not have a wp_term set up anymore at all, so this problem is likely to be at least 80% fixed. At that point, the limit will just be how many coauthors we are ignoring. For the search results to be empty, the post will have to have 10 coauthors already. If this happens often, we could bump the limit to 20 and we should be fine! Thoughts @philipjohn ? :)