WordPress / wp-plugin-dependencies

WordPress Feature Project: Plugin Dependencies
https://make.wordpress.org/core/2022/02/24/feature-project-plugin-dependencies/
MIT License
69 stars 9 forks source link

Optimisation: Add `dirname()` caching to `::get_dependency_filepaths()`. #21

Closed costdev closed 2 years ago

costdev commented 2 years ago

Previously, a nested foreach() meant that dirname() was called on plugins in each iteration of the parent foreach().

This PR adds two new private properties:

Now, dirname() will only be run on plugins if plugin_dirnames is empty, or has items but doesn't match plugin_dirnames_cache, which handles plugin changes during runtime. An additional PHPUnit test has been added to cover this latter case.

In addition, early returns have been added if $this->slugs or $this->plugins are empty.

Props to @jrfnl for help on this one!