yoast-acf-analysis
yoast-acf-analysis copied to clipboard
Too many AJAX requests from wp admin backend
- [x] I've read and understood the contribution guidelines.
- [x] 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?
- Open any post with ACF fields in wp backend editor
- 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
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] === "" )
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? 🌱