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 204 forks source link

Potential cache issue with ajax search on admin #849

Open jonathanstegall opened 2 years ago

jonathanstegall commented 2 years ago

Lately I've had issues with the admin search for co authors on posts. Only a few (maybe ten out of 2,000+) authors are appearing in the autosuggest. When I search for authors with known names that we've used, even very frequently, they don't show up. At first I thought it might be related to Elasticsearch because I had just updated our index before I noticed it (we host on WordPress VIP) and it was behaving differently across the different environments. It is broken in all three (develop, preprod, production) although the results are different across all three. I've yet to see any issues locally.

If my debugging is correct, I no longer think it's related to Elasticsearch because according to this method it's a SQL query that never runs through Elasticsearch. The results are stored in memcache though, so it could be a cache issue and that would also explain why it behaves differently between different environments. I've also noticed that sometimes it is different based on what user is logged in or what role they have, which I don't really have an explanation for.

The first few days I was able to cause an author record to show up in the results by editing its first or last name, but I'm having trouble getting even this to work after adding a new author. The newly added author does show up in the results.

I first noticed this all happening just last Friday, so I can't really see how it would be related to version 3.5.1 or anything like that. My first thought was that it had to be a hosting issue with VIP, maybe with the cache infrastructure, and maybe it is, but I'm also curious if there's anything I could investigate within Co-Authors-Plus that could solve this.

lschuyler commented 2 years ago

Hi @jonathanstegall,

Is this happening with the block editor? Or the classic editor? Or both?

jonathanstegall commented 2 years ago

I haven't used the block editor very heavily, so it may only be the classic editor.

jonathanstegall commented 2 years ago

Ultimately I've learned through VIP support that my issue is a duplicate of #622.

jonathanstegall commented 2 years ago

After looking into the fix that's on #622, I might be experiencing something different as neither of the filters mentioned as solutions caused any change for me.

jonathanstegall commented 2 years ago

In case it's helpful, I've found a way that does allow me to get results for the author Ajax search:

if ( ! function_exists( 'minnpost_coauthors_search_authors_get_terms_args' ) ) :
    add_filter( 'coauthors_search_authors_get_terms_args', 'minnpost_coauthors_search_authors_get_terms_args', 10, 1 );
    function minnpost_coauthors_search_authors_get_terms_args( $args ) {
        if ( is_admin() ) {
            $args['es']           = false;
            $args['ep_integrate'] = false;
        }
        return $args;
    }
endif;

I had tried using ep_integrate = true just to see if the extra flexibility would help, but this proved not to help. I had also tried using number = 0, thinking that if the large resultset loaded by Elasticsearch was the problem, maybe that would be the fix but it didn't help either.

So it does seem clear that, at least on a site with with a lot of author records (we have over 2,000) running the co author Ajax search query through Elasticsearch is not viable.