aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2025-05-07 14:06:56 -0100
committerMaxence Lange <maxence@artificial-owl.com>2025-05-07 14:08:10 -0100
commit62a82ae702d04aa2a68c9bffc2ce9b92965df8cd (patch)
tree77ee307f8a971f2cc621d73d54a9e184945bdc37
parent0dc971189badaf050fa5048e391c70fb15171b6f (diff)
downloadnextcloud-server-fix/noid/lexicon-update-lazy-status.tar.gz
nextcloud-server-fix/noid/lexicon-update-lazy-status.zip
feat(appconfig+userconfig): lexicon update lazy statusfix/noid/lexicon-update-lazy-status
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--lib/private/AppConfig.php8
-rw-r--r--lib/private/Config/UserConfig.php13
-rw-r--r--tests/lib/Config/LexiconTest.php80
-rw-r--r--tests/lib/Config/TestConfigLexicon_Migration.php36
4 files changed, 136 insertions, 1 deletions
diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php
index a8a6f689ffa..0a9c1ef98c8 100644
--- a/lib/private/AppConfig.php
+++ b/lib/private/AppConfig.php
@@ -969,7 +969,7 @@ class AppConfig implements IAppConfig {
if ($lazy === $this->isLazy($app, $key)) {
return false;
}
- } catch (AppConfigUnknownKeyException $e) {
+ } catch (AppConfigUnknownKeyException) {
return false;
}
@@ -1605,6 +1605,12 @@ class AppConfig implements IAppConfig {
$this->logger->notice('App config key ' . $app . '/' . $key . ' is set as deprecated.');
}
+ if ($lazy && isset($this->fastCache[$app][$key])) {
+ // while the Lexicon indicate that the config value is expected Lazy, we could
+ // have a previous entry still in fast cache. Updating Laziness.
+ $this->updateLazy($app, $key, true);
+ }
+
return true;
}
diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php
index 77a86a5e1c7..22588d5394d 100644
--- a/lib/private/Config/UserConfig.php
+++ b/lib/private/Config/UserConfig.php
@@ -1865,6 +1865,19 @@ class UserConfig implements IUserConfig {
$this->logger->notice('User config key ' . $app . '/' . $key . ' is set as deprecated.');
}
+ // There should be no downside to load all config values if search for
+ // a lazy config value while fast value are still not loaded.
+ if ($lazy && !($this->fastLoaded[$userId] ?? false)) {
+ $this->loadConfigAll($userId);
+ }
+
+ // while the Lexicon indicate that the config value is expected Lazy, we could
+ // have a previous entry still in fast cache. Updating Laziness for all users.
+ if ($lazy && isset($this->fastCache[$userId][$app][$key])) {
+ $this->updateGlobalLazy($app, $key, true);
+ }
+
+ // TODO: remove this feature before 32 if https://github.com/nextcloud/server/issues/51804 is implemented
$enforcedValue = $this->config->getSystemValue('lexicon.default.userconfig.enforced', [])[$app][$key] ?? false;
if (!$enforcedValue && $this->hasKey($userId, $app, $key, $lazy)) {
// if key exists there should be no need to extract default
diff --git a/tests/lib/Config/LexiconTest.php b/tests/lib/Config/LexiconTest.php
index 5bcd3509b22..8347e23909e 100644
--- a/tests/lib/Config/LexiconTest.php
+++ b/tests/lib/Config/LexiconTest.php
@@ -10,11 +10,17 @@ namespace Tests\lib\Config;
use NCU\Config\Exceptions\TypeConflictException;
use NCU\Config\Exceptions\UnknownKeyException;
use NCU\Config\IUserConfig;
+use OC\AppConfig;
use OC\AppFramework\Bootstrap\Coordinator;
+use OC\Config\UserConfig;
use OCP\Exceptions\AppConfigTypeConflictException;
use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IAppConfig;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Security\ICrypto;
use OCP\Server;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
/**
@@ -62,6 +68,80 @@ class LexiconTest extends TestCase {
$this->appConfig->deleteKey(TestConfigLexicon_E::APPID, 'key1');
}
+ public function testAppConfigMigrationToLazy() {
+ $app = TestConfigLexicon_Migration::APPID . '_app';
+ // to avoid filling cache with an empty Lexicon, we use a new IAppConfig
+ $appConfig = new AppConfig(
+ Server::get(IDBConnection::class),
+ Server::get(LoggerInterface::class),
+ Server::get(ICrypto::class),
+ );
+ $this->assertSame(true, $appConfig->setValueString($app, 'key1', 'value1'));
+
+ // confirm that key1 is not lazy, even after a refresh of the cache
+ $appConfig->clearCache();
+ $this->assertSame('value1', $appConfig->getValueString($app, 'key1'));
+ $this->assertSame(true, array_key_exists('key1', $appConfig->statusCache()['fastCache'][$app]));
+
+ // loading new Lexicon that set key1 as lazy
+ $bootstrapCoordinator = \OCP\Server::get(Coordinator::class);
+ $bootstrapCoordinator->getRegistrationContext()?->registerConfigLexicon($app, TestConfigLexicon_Migration::class);
+
+ // caching
+ $this->assertSame('default0', $this->appConfig->getValueString($app, 'key0'));
+ // still not lazy
+ $this->assertSame(true, array_key_exists('key1', $this->appConfig->statusCache()['fastCache'][$app]));
+ // trigger update of status
+ $this->assertSame('value1', $this->appConfig->getValueString($app, 'key1'));
+ // should be lazy now
+ $this->assertSame(true, array_key_exists('key1', $this->appConfig->statusCache()['lazyCache'][$app]));
+
+ $this->appConfig->clearCache();
+ $this->assertSame('default0', $this->appConfig->getValueString($app, 'key0'));
+ // definitively lazy
+ $this->assertSame(false, array_key_exists($app, $this->appConfig->statusCache()['fastCache']));
+
+ $this->appConfig->deleteKey($app, 'key1');
+ }
+
+ public function testUserConfigMigrationToLazy() {
+ $app = TestConfigLexicon_Migration::APPID . '_user';
+ // to avoid filling cache with an empty Lexicon, we use a new IAppConfig
+ $userConfig = new UserConfig(
+ Server::get(IDBConnection::class),
+ Server::get(IConfig::class),
+ Server::get(LoggerInterface::class),
+ Server::get(ICrypto::class),
+ );
+ $this->assertSame(true, $userConfig->setValueString('user1', $app, 'key1', 'value1'));
+
+ // confirm that key1 is not lazy, even after a refresh of Lexicon
+ $userConfig->clearCache('user1');
+ $this->assertSame('value1', $userConfig->getValueString('user1', $app, 'key1'));
+ $this->assertSame(true, array_key_exists('key1', $userConfig->statusCache()['fastCache']['user1'][$app]));
+
+ // loading new Lexicon that set key1 as lazy
+ $bootstrapCoordinator = \OCP\Server::get(Coordinator::class);
+ $bootstrapCoordinator->getRegistrationContext()?->registerConfigLexicon($app, TestConfigLexicon_Migration::class);
+
+ // caching
+ $this->assertSame('default0', $this->userConfig->getValueString('user1', $app, 'key0'));
+ // still not lazy
+ $this->assertSame(true, array_key_exists('key1', $this->userConfig->statusCache()['fastCache']['user1'][$app]));
+ // trigger update of status
+ $this->assertSame('value1', $this->userConfig->getValueString('user1', $app, 'key1'));
+ // should be lazy now
+ $this->assertSame(true, array_key_exists('key1', $this->userConfig->statusCache()['lazyCache']['user1'][$app]));
+
+ $this->userConfig->clearCache('user1');
+ $this->assertSame('default0', $this->userConfig->getValueString('user1', $app, 'key0'));
+ // definitively lazy
+ $this->assertSame(false, array_key_exists($app, $this->userConfig->statusCache()['fastCache']['user1']));
+
+ $this->userConfig->deleteKey($app, 'key1');
+ }
+
+
public function testAppLexiconGetCorrect() {
$this->assertSame('abcde', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key1', 'default'));
}
diff --git a/tests/lib/Config/TestConfigLexicon_Migration.php b/tests/lib/Config/TestConfigLexicon_Migration.php
new file mode 100644
index 00000000000..dfd34bd70d1
--- /dev/null
+++ b/tests/lib/Config/TestConfigLexicon_Migration.php
@@ -0,0 +1,36 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Tests\lib\Config;
+
+use NCU\Config\Lexicon\ConfigLexiconEntry;
+use NCU\Config\Lexicon\ConfigLexiconStrictness;
+use NCU\Config\Lexicon\IConfigLexicon;
+use NCU\Config\ValueType;
+
+class TestConfigLexicon_Migration implements IConfigLexicon {
+ public const APPID = 'lexicon_test_migration';
+
+ public function getStrictness(): ConfigLexiconStrictness {
+ return ConfigLexiconStrictness::EXCEPTION;
+ }
+
+ public function getAppConfigs(): array {
+ return [
+ new ConfigLexiconEntry('key0', ValueType::STRING, 'default0'),
+ new ConfigLexiconEntry('key1', ValueType::STRING, lazy: true)
+ ];
+ }
+
+ public function getUserConfigs(): array {
+ return [
+ new ConfigLexiconEntry('key0', ValueType::STRING, 'default0'),
+ new ConfigLexiconEntry('key1', ValueType::STRING, lazy: true)
+ ];
+ }
+}