Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ public function getApps(): array {
* @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 {
Expand All @@ -110,6 +111,32 @@ public function getKeys(string $app): array {
return array_values(array_unique($keys));
}

/**
* @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
*
Expand Down
16 changes: 15 additions & 1 deletion lib/public/IAppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,26 @@ public function getApps(): array;
* **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.
*
Expand Down
24 changes: 24 additions & 0 deletions tests/lib/AppConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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']
Expand Down Expand Up @@ -1439,6 +1446,23 @@ public function testUpdateNonSensitiveValueToSensitiveWithUpdateSensitive(): voi
$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')
Expand Down
Loading