rudrastyh / misha-update-checker

This simple plugin does nothing, only gets updates from a custom server
124 stars 44 forks source link

To many requests to the backend #16

Open kulbabskyy opened 9 months ago

kulbabskyy commented 9 months ago

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 commented 6 months ago

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.