Merge pull request #23032 from nextcloud/backport/23015/stable20

[stable20] Log slow dashboard widgets
This commit is contained in:
Roeland Jago Douma 2020-09-28 09:33:56 +02:00 committed by GitHub
commit 7496a10227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -95,7 +95,16 @@ class Manager implements IManager {
} }
try { try {
$startTime = microtime(true);
$widget->load(); $widget->load();
$endTime = microtime(true);
$duration = $endTime - $startTime;
if ($duration > 1) {
\OC::$server->getLogger()->error('Dashboard widget {widget} took {duration} seconds to load.', [
'widget' => $widget->getId(),
'duration' => round($duration, 2),
]);
}
} catch (Throwable $e) { } catch (Throwable $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Error during dashboard widget loading: ' . $e->getMessage(), 'message' => 'Error during dashboard widget loading: ' . $e->getMessage(),

View File

@ -72,7 +72,17 @@ class InitialStateService implements IInitialStateService {
private function invokeLazyStateCallbacks(): void { private function invokeLazyStateCallbacks(): void {
foreach ($this->lazyStates as $app => $lazyStates) { foreach ($this->lazyStates as $app => $lazyStates) {
foreach ($lazyStates as $key => $lazyState) { foreach ($lazyStates as $key => $lazyState) {
$startTime = microtime(true);
$this->provideInitialState($app, $key, $lazyState()); $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 = []; $this->lazyStates = [];