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

To many requests to the backend #16

Open
kulbabskyy opened this issue Jan 18, 2024 · 1 comment
Open

To many requests to the backend #16

kulbabskyy opened this issue Jan 18, 2024 · 1 comment

Comments

@kulbabskyy
Copy link

kulbabskyy commented Jan 18, 2024

Hello,

I've encountered an issue with my custom update script in a WordPress plugin when caching is disabled. The problem arises irrespective of which admin page is accessed, resulting in multiple unnecessary remote requests.

The relevant part of my __construct() function looks like this:

public function __construct() { $this->cache_allowed = true; }
Despite this setting, the update function $this->request() is being called multiple times (around 9 times) during a single admin page load. This behavior seems to occur on every admin page load, leading to a significant number of redundant requests to my backend.

I have calculated how the many times the function is called:
int(1) int(2) int(3) int(4) int(5) int(6) int(7) int(8) int(9)

This issue appears to be related to the number of plugins installed on the site (currently, I have only three plugins, including the one with this update functionality).

I am seeking advice or solutions to optimize the update check mechanism to prevent these excessive requests. Any insights or recommendations would be greatly appreciated.

Thank you!

@brasofilo
Copy link

brasofilo commented Apr 29, 2024

We can minimize the issue running the offending code like this:

add_action( 'load-plugins.php', function() {
    add_filter( 'site_transient_update_plugins', [$this, 'update'] );
});

update

I didn't have the cache_allowed enabled, once I set it to true, the problem disappeared.

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

2 participants