Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#42217 new enhancement

Plugins misuse get_plugins(), should be cached

Reported by: fabifott's profile fabifott Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Plugins Keywords:
Focuses: performance Cc:


Many popular plugins misuse get_plugins(). They call it to check if a certain extension is available, and they do it every request.
This is the actual reason why it is recommended to keep your plugins directory clean.

I tried to reach some of the plugin devs telling them that they are using get_plugins() in a wrong way, but they did not listen.

get_plugins() uses the non-persistent object cache. Once there is some plugin call it, it will scan the plugin directory. It depending on your number of installed plugins, this can take a while. (On VVV, host i7 skylake with NVME SSD, 32 plugins in the plugins dir, 400 - 600 ms). Any subsequent calls during the same request are at no cost.

For a fix I propose to use an additional transient for caching. This transient should have a lifetime of at least 1 hour. To be able to instantly find plugins that have been installed or updated on the file system, this transient should be deleted on every request of the plugins admin screen. Additionally, it can be refreshed on every cron request.

This would significantly increase performance of the dashboard, if there is at least one plugin misusing get_plugins().

Change History (2)

#1 @dd32
7 years ago

I feel like this is firmly square in the doing-it-wrong category, and is a performance bug that should be fixed in the plugin.

I'd be very interested in knowing if any plugins hosted on use the function on every page load, especially as it's intended for admin-only usage.

#2 @afragen
7 years ago

I feel I should comment as the plugin in question is mine, though not in dot org. It only called get_plugins() on specific admin pages and never on the frontend.

I believe I’ve figured out a way to cache this data for a short time, but as the plugin is an updater it relies on know if/when new plugins are added.

The specific issue is on GitHub,

Note: See TracTickets for help on using tickets.