Skip to content

Commit 76b8024

Browse files
committed
fix(CapabilitiesManager): only check execution time if debug mode is enabled
Signed-off-by: Simon L. <szaimen@e.mail.de>
1 parent 46f61ca commit 76b8024

1 file changed

Lines changed: 24 additions & 20 deletions

File tree

lib/private/CapabilitiesManager.php

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,30 @@ public function getCapabilities(bool $public = false, bool $initialState = false
5656
// that we would otherwise inject to every page load
5757
continue;
5858
}
59-
$startTime = microtime(true);
60-
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
61-
$endTime = microtime(true);
62-
$timeSpent = $endTime - $startTime;
63-
if ($timeSpent > self::ACCEPTABLE_LOADING_TIME) {
64-
$logLevel = match (true) {
65-
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 16 => ILogger::FATAL,
66-
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 8 => ILogger::ERROR,
67-
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 4 => ILogger::WARN,
68-
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 2 => ILogger::INFO,
69-
default => ILogger::DEBUG,
70-
};
71-
$this->logger->log(
72-
$logLevel,
73-
'Capabilities of {className} took {duration} seconds to generate.',
74-
[
75-
'className' => get_class($c),
76-
'duration' => round($timeSpent, 2),
77-
]
78-
);
59+
60+
// Only check execution time if debug mode is enabled
61+
if (\OCP\Server::get(\OCP\IConfig::class)->getSystemValueBool('debug', false) === true) {
62+
$startTime = microtime(true);
63+
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
64+
$endTime = microtime(true);
65+
$timeSpent = $endTime - $startTime;
66+
if ($timeSpent > self::ACCEPTABLE_LOADING_TIME) {
67+
$logLevel = match (true) {
68+
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 16 => ILogger::FATAL,
69+
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 8 => ILogger::ERROR,
70+
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 4 => ILogger::WARN,
71+
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 2 => ILogger::INFO,
72+
default => ILogger::DEBUG,
73+
};
74+
$this->logger->log(
75+
$logLevel,
76+
'Capabilities of {className} took {duration} seconds to generate.',
77+
[
78+
'className' => get_class($c),
79+
'duration' => round($timeSpent, 2),
80+
]
81+
);
82+
}
7983
}
8084
}
8185
} else {

0 commit comments

Comments
 (0)