-
Couldn't load subscription status.
- Fork 11.6k
[11.x] Optimize commands registry #52928
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
Conversation
61b4283 to
5d35dae
Compare
|
Nice idea @erikgaal! I'd be inclined to have the third-party packages have the commands register as optimisation and optimisation clearing commands, similar to how you can register publishable assets. $this->registerOptimizationCommands(
optimization: 'icons:cache',
optimizationClearing: 'icons:clear'
);That way it's not silent, and then it opens you up to an interactive command, something like php artisan optimize --selectThat lets you select specifically which things you want to optimise. That's my thinking on this, for whatever it's worth. Either way, good work so far and good luck with the PR. |
5d35dae to
531e7f0
Compare
531e7f0 to
ec5b9a7
Compare
|
Hey @ollieread, thanks for the suggestion. I think it aligns perfectly with what I had in mind earlier. I've updated the PR with the new implementation! 🚀 |
ec5b9a7 to
bd51e17
Compare
| 'cache' => 'cache:clear', | ||
| 'compiled' => 'clear-compiled', | ||
| 'config' => 'config:clear', | ||
| 'events' => 'event:clear', | ||
| 'routes' => 'route:clear', | ||
| 'views' => 'view:clear', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could be registered in the respective service providers that are responsible for adding these commands/functionalities?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could be registered in the respective service providers that are responsible for adding these commands/functionalities?
Good call, but, the order may be important
38088eb to
62b5698
Compare
62b5698 to
5e8231e
Compare
|
This is so useful |
|
I would actually prefer just having the events like you originally had. 🫠 Please mark as ready for review when the requested changes have been made. |
|
That would mean
Let me know what option you prefer and I'll get it done. |
I would actually prefer something like this: or Alternatively, couldn't classes just implement something like a |
|
Thanks @erikgaal - tweaked a few things. 👍 |
Motivation
From the docs:
Other than the caching commands the framework uses by default, third-party packages often also have similar commands:
icons:cache&&icons:clearevent-sourcing:cache-event-handlers&&event-sourcing:clear-event-handlersdata:cache-structuresOf course, developers are expected to read integration guides so they can install and configure packages accordingly. However, sometimes deployment optimization steps like these are forgotten about (I'm personally the prime example of that 🙈). Packages usually just work if you forget this but are running with sub-optimal performance costing more compute time ⏱️ , energy ⚡ and money 💰 as a result.
Wouldn't it be great that every package you install does these optimization steps automatically?
Implementation
This addition surfaces an extension point packages can use to run their own optimization handlers to be automatically run when the
artisan optimizeandartisan optimize:clearcommands run.It works by having an event be dispatched (OptimizingandOptimizeClearing) whenever theartisan optimizecommand runs. Packages can then register an event listener in their service providers that run the optimization step they need to do.A previous implementation worked by dispatching special events that package developers could hook into. After consideration, I've taken a different approach similar to how publishes are registered in Service Providers.
The
ServiceProviderclass now offers aregisterOptimizeCommands()method that can be used to register a command that should run during theoptimizeandoptimize:clearcommands. It also allows you to provide akeywhich is used to show the step in the command output.Example:
Running the
optimizecommand will now also output all the optimization commands that ran:Todo
optimizeandoptimize:clearcommands were backported to earlier versions of Laravel, do we want to do that with this PR too?