From b1f07e887e603d53617f7cff08339eabef73af76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 7 Apr 2026 16:18:33 +0200 Subject: [PATCH] fix: Remove static vars in preview Generator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is only one instance so caching in a property is enough. There were two levels of caching, removed one. Signed-off-by: Côme Chilliet --- lib/private/Preview/Generator.php | 33 ++++++++++++------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index 403e76f6f0e..88776978282 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -34,6 +34,8 @@ class Generator { public const SEMAPHORE_ID_ALL = 0x0a11; public const SEMAPHORE_ID_NEW = 0x07ea; + private array $cachedNumConcurrentPreviews = []; + public function __construct( private readonly IConfig $config, private readonly IAppConfig $appConfig, @@ -259,22 +261,14 @@ class Generator { * * @return int number of concurrent threads, or 0 if it cannot be determined */ - public static function getHardwareConcurrency(): int { - static $width; - - if (!isset($width)) { - if (function_exists('ini_get')) { - $openBasedir = ini_get('open_basedir'); - if (empty($openBasedir) || strpos($openBasedir, '/proc/cpuinfo') !== false) { - $width = is_readable('/proc/cpuinfo') ? substr_count(file_get_contents('/proc/cpuinfo'), 'processor') : 0; - } else { - $width = 0; - } - } else { - $width = 0; + private static function getHardwareConcurrency(): int { + if (function_exists('ini_get')) { + $openBasedir = ini_get('open_basedir'); + if (empty($openBasedir) || strpos($openBasedir, '/proc/cpuinfo') !== false) { + return is_readable('/proc/cpuinfo') ? substr_count(file_get_contents('/proc/cpuinfo'), 'processor') : 0; } } - return $width; + return 0; } /** @@ -293,9 +287,8 @@ class Generator { * @return int number of concurrent preview generations, or -1 if $type is invalid */ public function getNumConcurrentPreviews(string $type): int { - static $cached = []; - if (array_key_exists($type, $cached)) { - return $cached[$type]; + if (array_key_exists($type, $this->cachedNumConcurrentPreviews)) { + return $this->cachedNumConcurrentPreviews[$type]; } $hardwareConcurrency = self::getHardwareConcurrency(); @@ -304,16 +297,16 @@ class Generator { $fallback = $hardwareConcurrency > 0 ? $hardwareConcurrency * 2 : 8; $concurrency_all = $this->config->getSystemValueInt($type, $fallback); $concurrency_new = $this->getNumConcurrentPreviews('preview_concurrency_new'); - $cached[$type] = max($concurrency_all, $concurrency_new); + $this->cachedNumConcurrentPreviews[$type] = max($concurrency_all, $concurrency_new); break; case 'preview_concurrency_new': $fallback = $hardwareConcurrency > 0 ? $hardwareConcurrency : 4; - $cached[$type] = $this->config->getSystemValueInt($type, $fallback); + $this->cachedNumConcurrentPreviews[$type] = $this->config->getSystemValueInt($type, $fallback); break; default: return -1; } - return $cached[$type]; + return $this->cachedNumConcurrentPreviews[$type]; } /**