aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2025-07-18 13:16:39 -0100
committerMaxence Lange <maxence@artificial-owl.com>2025-07-18 23:54:55 -0100
commit20b908cf3fc5d8f47652192cfb07127fd484226c (patch)
tree05f24349c39fbb25a3342c189a19b2c1375122e8
parentc4b11e8a6db733c27f958daa6eead4576f8d3348 (diff)
downloadnextcloud-server-enh/noid/appconfig-get-fast-keys.tar.gz
nextcloud-server-enh/noid/appconfig-get-fast-keys.zip
feat(appconfig): add searchKeys()enh/noid/appconfig-get-fast-keys
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--lib/private/AppConfig.php29
-rw-r--r--lib/public/IAppConfig.php16
-rw-r--r--tests/lib/AppConfigTest.php24
3 files changed, 67 insertions, 2 deletions
diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php
index 0eb91fb1be4..f050deba1ca 100644
--- a/lib/private/AppConfig.php
+++ b/lib/private/AppConfig.php
@@ -95,8 +95,9 @@ class AppConfig implements IAppConfig {
* @inheritDoc
*
* @param string $app id of the app
- *
* @return list<string> list of stored config keys
+ * @see searchKeys to not load lazy config keys
+ *
* @since 29.0.0
*/
public function getKeys(string $app): array {
@@ -112,6 +113,32 @@ class AppConfig implements IAppConfig {
* @inheritDoc
*
* @param string $app id of the app
+ * @param string $prefix returns only keys starting with this value
+ * @param bool $lazy TRUE to search in lazy config keys
+ * @return list<string> list of stored config keys
+ * @since 32.0.0
+ */
+ public function searchKeys(string $app, string $prefix = '', bool $lazy = false): array {
+ $this->assertParams($app);
+ $this->loadConfig($app, $lazy);
+ if ($lazy) {
+ $keys = array_keys($this->lazyCache[$app] ?? []);
+ } else {
+ $keys = array_keys($this->fastCache[$app] ?? []);
+ }
+
+ if ($prefix !== '') {
+ $keys = array_filter($keys, static fn (string $key): bool => str_starts_with($key, $prefix));
+ }
+
+ sort($keys);
+ return array_values(array_unique($keys));
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @param string $app id of the app
* @param string $key config key
* @param bool|null $lazy TRUE to search within lazy loaded config, NULL to search within all config
*
diff --git a/lib/public/IAppConfig.php b/lib/public/IAppConfig.php
index fcc528fe11f..68d4332146e 100644
--- a/lib/public/IAppConfig.php
+++ b/lib/public/IAppConfig.php
@@ -65,13 +65,27 @@ interface IAppConfig {
* **WARNING:** ignore lazy filtering, all config values are loaded from database
*
* @param string $app id of the app
- *
* @return list<string> list of stored config keys
+ * @see searchKeys to avoid loading lazy config keys
+ *
* @since 29.0.0
*/
public function getKeys(string $app): array;
/**
+ * Returns list of keys stored in database, related to an app.
+ * Please note that the values are not returned.
+ *
+ * @param string $app id of the app
+ * @param string $prefix returns only keys starting with this value
+ * @param bool $lazy TRUE to search in lazy config keys
+ *
+ * @return list<string> list of stored config keys
+ * @since 32.0.0
+ */
+ public function searchKeys(string $app, string $prefix = '', bool $lazy = false): array;
+
+ /**
* Check if a key exists in the list of stored config values.
*
* @param string $app id of the app
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php
index 4c579bc4f09..03405bf96ca 100644
--- a/tests/lib/AppConfigTest.php
+++ b/tests/lib/AppConfigTest.php
@@ -47,6 +47,13 @@ class AppConfigTest extends TestCase {
'deletethis' => ['deletethis', 'deletethis'],
'key' => ['key', 'value']
],
+ 'searchtest' => [
+ 'search_key1' => ['search_key1', 'key1', IAppConfig::VALUE_STRING],
+ 'search_key2' => ['search_key2', 'key2', IAppConfig::VALUE_STRING],
+ 'search_key3' => ['search_key3', 'key3', IAppConfig::VALUE_STRING],
+ 'searchnot_key4' => ['searchnot_key4', 'key4', IAppConfig::VALUE_STRING],
+ 'search_key5_lazy' => ['search_key5_lazy', 'key5', IAppConfig::VALUE_STRING, true],
+ ],
'someapp' => [
'key' => ['key', 'value'],
'otherkey' => ['otherkey', 'othervalue']
@@ -1454,6 +1461,23 @@ class AppConfigTest extends TestCase {
$this->assertConfigValueNotEquals('testapp', $key, $secret);
}
+ public function testSearchKeyNoLazyLoading(): void {
+ $appConfig = $this->generateAppConfig();
+ $appConfig->searchKeys('searchtest', 'search_');
+ $status = $appConfig->statusCache();
+ $this->assertFalse($status['lazyLoaded'], 'searchKeys() loaded lazy config');
+ }
+
+ public function testSearchKeyFast(): void {
+ $appConfig = $this->generateAppConfig();
+ $this->assertEquals(['search_key1', 'search_key2', 'search_key3'], $appConfig->searchKeys('searchtest', 'search_'));
+ }
+
+ public function testSearchKeyLazy(): void {
+ $appConfig = $this->generateAppConfig();
+ $this->assertEquals(['search_key5_lazy'], $appConfig->searchKeys('searchtest', 'search_', true));
+ }
+
protected function loadConfigValueFromDatabase(string $app, string $key): string|false {
$sql = $this->connection->getQueryBuilder();
$sql->select('configvalue')