Skip to content

Lazy-load console commands registration to avoid overhead in HTTP requests#23

Open
norbybaru wants to merge 1 commit into
masterfrom
auto-claude/015-lazy-load-console-commands-registration-to-avoid-o
Open

Lazy-load console commands registration to avoid overhead in HTTP requests#23
norbybaru wants to merge 1 commit into
masterfrom
auto-claude/015-lazy-load-console-commands-registration-to-avoid-o

Conversation

@norbybaru
Copy link
Copy Markdown
Owner

In registerMakeCommand(), all 17 module:make:* command classes are registered via $this->commands() during every request cycle, including HTTP requests. While autoloadConsoleCommands() correctly checks runningInConsole(), the registerMakeCommand() in register() only checks runningInConsole() at the call site but still eagerly resolves command class autoloading.

…gisterMakeCommand()

Convert eager command class imports to lazy loading using fully qualified class name strings.
This prevents autoloading overhead for command classes during HTTP requests.

- Removed 20 command class use statements
- Updated registerMakeCommand() to use string FQCNs instead of Class::class
- Maintains identical functionality via Laravel's lazy command resolution

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to reduce non-console request overhead by making console command registration “lazy” (avoiding eager command class loading/registration work during HTTP requests).

Changes:

  • Removed use imports for all module:make:* and module:list command classes.
  • Replaced SomeCommand::class entries with hard-coded fully-qualified class-name strings in registerMakeCommand().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 271 to +275
$this->commands([
ModuleMakeComponentCommand::class,
ModuleMakeConsoleCommand::class,
ModuleMakeControllerCommand::class,
ModuleMakeEventCommand::class,
ModuleMakeFactoryCommand::class,
ModuleMakeJobCommand::class,
ModuleListCommand::class,
ModuleMakeListenerCommand::class,
ModuleMakeMailCommand::class,
ModuleMakeModelCommand::class,
ModuleMakeMiddlewareCommand::class,
ModuleMakeMigrationCommand::class,
ModuleMakeNotificationCommand::class,
ModuleMakeProviderCommand::class,
ModuleMakePolicyCommand::class,
ModuleMakeResourceCommand::class,
ModuleMakeRequestCommand::class,
ModuleMakeSeederCommand::class,
ModuleMakeTestCommand::class,
ModuleMakeViewCommand::class,
'NorbyBaru\Modularize\Console\Commands\ModuleMakeComponentCommand',
'NorbyBaru\Modularize\Console\Commands\ModuleMakeConsoleCommand',
'NorbyBaru\Modularize\Console\Commands\ModuleMakeControllerCommand',
'NorbyBaru\Modularize\Console\Commands\ModuleMakeEventCommand',
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These registrations were changed from ImportedCommand::class to hard-coded class-name strings. Foo\\Bar::class already resolves to a string without requiring the class to be loaded, so this likely doesn’t reduce overhead but does reduce refactor safety (renames won’t be caught) and static analysis/IDE support. Prefer keeping the use ... imports and passing ::class constants.

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

3 participants