Yoast / yoast-acf-analysis

WordPress plugin that adds the content of all ACF fields to the Yoast SEO score analysis.
https://wordpress.org/plugins/acf-content-analysis-for-yoast-seo/
GNU General Public License v3.0
62 stars 20 forks source link

Too many AJAX requests from wp admin backend #309

Open kylokean opened 2 years ago

kylokean commented 2 years ago

Please give us a description of what happened.

It seems that we are doing a lots of AJAX requests from the admin backend when this plugin is enabled. It causes abnormal >1000% CPU load.

We already removed image and gallery field types from scoring as described below - it reduced ajax requests but it didn't fix this problem 100% => add_filter( 'yoast-acf-analysis/blacklist_type', function ( $blacklist_type ) { $blacklist_type->add( 'image' ); $blacklist_type->add( 'gallery' ); return $blacklist_type; });

Please describe what you expected to happen and why.

We are expected to reduce ajax requests.

As a possible solution we want to try to Change refresh rate as described in your documentation => add_filter( 'Yoast\WP\ACF\refresh_rate', function () { // Refresh rates in milliseconds return 3000; });

But we need to know what is the default value (1000?), min and max values and how to easily check in browser current value of 'refresh_rate' to see that our changes applied successfully.

How can we reproduce this behavior?

  1. Open any post with ACF fields in wp backend editor
  2. Open google chrome/Dev Tools/Network/Fetch/XHR - https://prnt.sc/hG7hVKRZ3RVr

Technical info

rvdsteege commented 1 year ago

Running into the same issue and did some research. I'm not sure if it is the same in your case, but I noticed a lot of requests originating from a refresh function which queries attachments:

https://github.com/Yoast/yoast-acf-analysis/blob/4c622547ce223be4aeba2e3d103f6499c9a54680/js/src/cache/cache.attachments.js#L4-L21

While editing posts, admin-ajax.php seems to be requested over and over again while the given post__in parameter only contains an array with an empty string ([ "" ]). As no posts are being queried and there will never be any results in this case, it is wasting server resources and this call should not be performed at all (that is probably also where uncached.length === 0 is intended for, but seems there's an issue with that check as uncached is an array with empty strings).

As a temporary solution, I've manually changed the if-statement in /js/yoast-acf-analysis.js from:

if ( uncached.length === 0 )

to:

if ( uncached.length === 0 || uncached[0] === "" )

remcotolsma commented 1 year ago

This continues to cause performance issues, it would be nice if the @Yoast team would fix this. I think my colleague @rvdsteege has already provided the solution. Because of this issue, admin-ajax.php has been at the top of the list of most visited pages for months. Can you maybe take a look at this @enricobattocchi? 🌱

Scherm­afbeelding 2023-06-26 om 10 57 26