From 89aa1ed537b0e033888dfe65d725ea64ca1d612d Mon Sep 17 00:00:00 2001 From: "Simon L." Date: Mon, 16 Mar 2026 11:34:08 +0100 Subject: [PATCH] fix(CapabilitiesManager): only check execution time if debug mode is enabled Signed-off-by: Simon L. --- lib/private/CapabilitiesManager.php | 41 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/private/CapabilitiesManager.php b/lib/private/CapabilitiesManager.php index 494504af3d80a..de267f568a7cb 100644 --- a/lib/private/CapabilitiesManager.php +++ b/lib/private/CapabilitiesManager.php @@ -12,6 +12,7 @@ use OCP\Capabilities\ICapability; use OCP\Capabilities\IInitialStateExcludedCapability; use OCP\Capabilities\IPublicCapability; +use OCP\IConfig; use OCP\ILogger; use Psr\Log\LoggerInterface; @@ -56,26 +57,32 @@ public function getCapabilities(bool $public = false, bool $initialState = false // that we would otherwise inject to every page load continue; } + $startTime = microtime(true); $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); $endTime = microtime(true); - $timeSpent = $endTime - $startTime; - if ($timeSpent > self::ACCEPTABLE_LOADING_TIME) { - $logLevel = match (true) { - $timeSpent > self::ACCEPTABLE_LOADING_TIME * 16 => ILogger::FATAL, - $timeSpent > self::ACCEPTABLE_LOADING_TIME * 8 => ILogger::ERROR, - $timeSpent > self::ACCEPTABLE_LOADING_TIME * 4 => ILogger::WARN, - $timeSpent > self::ACCEPTABLE_LOADING_TIME * 2 => ILogger::INFO, - default => ILogger::DEBUG, - }; - $this->logger->log( - $logLevel, - 'Capabilities of {className} took {duration} seconds to generate.', - [ - 'className' => get_class($c), - 'duration' => round($timeSpent, 2), - ] - ); + + // Only check execution time if debug mode is enabled + $debugMode = \OCP\Server::get(IConfig::class)->getSystemValueBool('debug', false); + if ($debugMode) { + $timeSpent = $endTime - $startTime; + if ($timeSpent > self::ACCEPTABLE_LOADING_TIME) { + $logLevel = match (true) { + $timeSpent > self::ACCEPTABLE_LOADING_TIME * 16 => ILogger::FATAL, + $timeSpent > self::ACCEPTABLE_LOADING_TIME * 8 => ILogger::ERROR, + $timeSpent > self::ACCEPTABLE_LOADING_TIME * 4 => ILogger::WARN, + $timeSpent > self::ACCEPTABLE_LOADING_TIME * 2 => ILogger::INFO, + default => ILogger::DEBUG, + }; + $this->logger->log( + $logLevel, + 'Capabilities of {className} took {duration} seconds to generate.', + [ + 'className' => get_class($c), + 'duration' => round($timeSpent, 2), + ] + ); + } } } } else {