Skip to content
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

Make services lazy #66

Merged
merged 1 commit into from
Jan 15, 2025
Merged

Conversation

WedgeSama
Copy link
Contributor

Description

Some compute are done when services are instantiated (e.g. injected). Better to compute only if the service is really used.

Why did I do that? Multiple reasons:

  • Optimize the services creation, less compute if not needed
  • Fix cases when you when your app to work (composer install, page rendering, etc...) without having a credentials.json
  • Do not change how most of the bundle works

Plus some optimizations:

  • ProjectFactory service do not need Factory factory injection (no argument in its constructor).
  • ProjectFactory::createFactory if we really want a new instance, use new instead of clone to ensure it.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works (only update 2 tests to load lazy service)
  • I have made corresponding changes to the documentation (does not need any change)

Too many compute done when services are instantiated (e.g. injected). Better to compute only if the service is really used.
Plus some optim:
- `ProjectFactory` service do not need `Factory` factory injection (no argument in its constructor).
- `ProjectFactory::createFactory` if we really want a new instance, use `new` instead of `clone`.
@jeromegamez
Copy link
Member

Makes total sense! Thanks a lot for your contribution!

@jeromegamez jeromegamez merged commit 61c2a4c into kreait:main Jan 15, 2025
@WedgeSama
Copy link
Contributor Author

My pleasure 😉

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.

2 participants