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

[perf] Call Factory::first once and cache the result in FactoryServiceProvider #361

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/Providers/FactoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class FactoryServiceProvider extends ServiceProvider
{
/**
* The first factory
*
* @var static|null
*/
private static ?Factory $firstFactory = null;

/**
* Register services.
*/
Expand All @@ -21,10 +28,10 @@ public function register(): void
*/
public function boot()
{
//view()->share('Factory', Factory::first());
self::$firstFactory ??= Factory::first();
//view()->share('Factory', self::$firstFactory);
View::composer('*', function ($view) {
$Factory = Factory::first();
$view->with('Factory', $Factory);
$view->with('Factory', self::$firstFactory);
});
}
}