mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 18:50:47 -04:00
fix: Remove static vars in preview Generator
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 <come.chilliet@nextcloud.com>
This commit is contained in:
parent
2ef982d402
commit
b1f07e887e
1 changed files with 13 additions and 20 deletions
|
|
@ -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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue