fix: Move getAppInstalledVersions to AppConfig so that it can be used earlier

Call it from OC_App to make sure there is only one request to DB.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/51676/head
Côme Chilliet 2025-03-25 16:18:51 +07:00
parent 1ae3e8e77d
commit c7037d7b38
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
6 changed files with 38 additions and 19 deletions

@ -19,7 +19,6 @@ use OCP\Collaboration\AutoComplete\IManager as IAutoCompleteManager;
use OCP\Collaboration\Collaborators\ISearch as ICollaboratorSearch;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IGroup;
@ -818,13 +817,7 @@ class AppManager implements IAppManager {
* @return array<string, string>
*/
public function getAppInstalledVersions(): array {
static $versions;
if (!$versions) {
/** @var array<string, string> */
$versions = $this->getAppConfig()->searchValues('installed_version', false, IAppConfig::VALUE_STRING);
}
return $versions;
return $this->getAppConfig()->getAppInstalledVersions();
}
/**

@ -62,6 +62,9 @@ class AppConfig implements IAppConfig {
/** @var array<array-key, array{entries: array<array-key, ConfigLexiconEntry>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */
private array $configLexiconDetails = [];
/** @var ?array<string, string> */
private ?array $appVersionsCache = null;
public function __construct(
protected IDBConnection $connection,
protected LoggerInterface $logger,
@ -1647,4 +1650,17 @@ class AppConfig implements IAppConfig {
return $this->configLexiconDetails[$appId];
}
/**
* Returns the installed versions of all apps
*
* @return array<string, string>
*/
public function getAppInstalledVersions(): array {
if ($this->appVersionsCache === null) {
/** @var array<string, string> */
$this->appVersionsCache = $this->searchValues('installed_version', false, IAppConfig::VALUE_STRING);
}
return $this->appVersionsCache;
}
}

@ -337,4 +337,13 @@ class AppConfig implements IAppConfig {
public function deleteUserValue(string $userId, string $key): void {
$this->config->deleteUserValue($userId, $this->appName, $key);
}
/**
* Returns the installed versions of all apps
*
* @return array<string, string>
*/
public function getAppInstalledVersions(): array {
return $this->appConfig->getAppInstalledVersions();
}
}

@ -610,7 +610,7 @@ class Server extends ServerContainer implements IServerContainer {
$prefixClosure = function () use ($logQuery, $serverVersion): ?string {
if (!$logQuery) {
try {
$v = \OC_App::getAppVersions();
$v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions();
} catch (\Doctrine\DBAL\Exception $e) {
// Database service probably unavailable
// Probably related to https://github.com/nextcloud/server/issues/37424

@ -642,17 +642,10 @@ class OC_App {
/**
* get the installed version of all apps
* @deprecated 32.0.0 Use IAppManager::getAppInstalledVersions instead
* @deprecated 32.0.0 Use IAppManager::getAppInstalledVersions or IAppConfig::getAppInstalledVersions instead
*/
public static function getAppVersions() {
static $versions;
if (!$versions) {
/** @var IAppConfig $appConfig */
$appConfig = \OCP\Server::get(IAppConfig::class);
$versions = $appConfig->searchValues('installed_version');
}
return $versions;
public static function getAppVersions(): array {
return \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions();
}
/**

@ -507,4 +507,12 @@ interface IAppConfig {
* @deprecated 29.0.0 Use {@see getAllValues()} or {@see searchValues()}
*/
public function getFilteredValues($app);
/**
* Returns the installed version of all apps
*
* @return array<string, string>
* @since 32.0.0
*/
public function getAppInstalledVersions(): array;
}