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

Too many AJAX requests from wp admin backend #309

Open
2 tasks done
kylokean opened this issue May 10, 2022 · 2 comments
Open
2 tasks done

Too many AJAX requests from wp admin backend #309

kylokean opened this issue May 10, 2022 · 2 comments

Comments

@kylokean
Copy link

kylokean commented May 10, 2022

  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

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

  • WordPress version: 5.9.3
  • ACF Content Analysis for Yoast SEO version: 3.0.1
  • Yoast SEO 18.8
  • Yoast SEO Premium 18.4
  • ACF type: Pro
  • ACF version: 5.12.2
  • PHP 7.4
@rvdsteege
Copy link

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:

var refresh = function( attachment_ids ) {
var uncached = cache.getUncached( attachment_ids, "attachment" );
if ( uncached.length === 0 ) {
return;
}
window.wp.ajax.post( "query-attachments", {
query: {
post__in: uncached,
},
} ).done( function( attachments ) {
_.each( attachments, function( attachment ) {
cache.set( attachment.id, attachment, "attachment" );
window.YoastACFAnalysis.maybeRefresh();
} );
} );
};

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
Copy link

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

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

No branches or pull requests

3 participants