Log a warning if a "lazy" initial state loads longer than 1 second

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-09-23 12:14:31 +02:00 committed by backportbot[bot]
parent 87f8e1e366
commit 5475bb4083
1 changed files with 10 additions and 0 deletions

View File

@ -72,7 +72,17 @@ class InitialStateService implements IInitialStateService {
private function invokeLazyStateCallbacks(): void {
foreach ($this->lazyStates as $app => $lazyStates) {
foreach ($lazyStates as $key => $lazyState) {
$startTime = microtime(true);
$this->provideInitialState($app, $key, $lazyState());
$endTime = microtime(true);
$duration = $endTime - $startTime;
if ($duration > 1) {
$this->logger->warning('Lazy initial state provider for {key} took {duration} seconds.', [
'app' => $app,
'key' => $key,
'duration' => round($duration, 2),
]);
}
}
}
$this->lazyStates = [];