Skip to content

Commit

Permalink
feat(appconfig): Only log lazy-appconfig when an app can do something…
Browse files Browse the repository at this point in the history
… about it

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Oct 20, 2024
1 parent 64cbf91 commit 09f98b5
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getApps(): array {
*/
public function getKeys(string $app): array {
$this->assertParams($app);
$this->loadConfigAll();
$this->loadConfigAll($app);
$keys = array_merge(array_keys($this->fastCache[$app] ?? []), array_keys($this->lazyCache[$app] ?? []));
sort($keys);

Expand All @@ -117,7 +117,7 @@ public function getKeys(string $app): array {
*/
public function hasKey(string $app, string $key, ?bool $lazy = false): bool {
$this->assertParams($app, $key);
$this->loadConfig($lazy);
$this->loadConfig($app, $lazy);

if ($lazy === null) {
$appCache = $this->getAllValues($app);
Expand All @@ -142,7 +142,7 @@ public function hasKey(string $app, string $key, ?bool $lazy = false): bool {
*/
public function isSensitive(string $app, string $key, ?bool $lazy = false): bool {
$this->assertParams($app, $key);
$this->loadConfig($lazy);
$this->loadConfig(null, $lazy);

if (!isset($this->valueTypes[$app][$key])) {
throw new AppConfigUnknownKeyException('unknown config key');
Expand Down Expand Up @@ -190,7 +190,7 @@ public function isLazy(string $app, string $key): bool {
public function getAllValues(string $app, string $prefix = '', bool $filtered = false): array {
$this->assertParams($app, $prefix);
// if we want to filter values, we need to get sensitivity
$this->loadConfigAll();
$this->loadConfigAll($app);
// array_merge() will remove numeric keys (here config keys), so addition arrays instead
$values = $this->formatAppValues($app, ($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? []));
$values = array_filter(
Expand Down Expand Up @@ -234,7 +234,7 @@ function (string $key) use ($prefix): bool {
*/
public function searchValues(string $key, bool $lazy = false, ?int $typedAs = null): array {
$this->assertParams('', $key, true);
$this->loadConfig($lazy);
$this->loadConfig(null, $lazy);

/** @var array<array-key, array<array-key, mixed>> $cache */
if ($lazy) {
Expand Down Expand Up @@ -430,7 +430,7 @@ private function getTypedValue(
int $type,
): string {
$this->assertParams($app, $key, valueType: $type);
$this->loadConfig($lazy);
$this->loadConfig($app, $lazy);

/**
* We ignore check if mixed type is requested.
Expand Down Expand Up @@ -487,7 +487,7 @@ private function getTypedValue(
*/
public function getValueType(string $app, string $key, ?bool $lazy = null): int {
$this->assertParams($app, $key);
$this->loadConfig($lazy);
$this->loadConfig($app, $lazy);

if (!isset($this->valueTypes[$app][$key])) {
throw new AppConfigUnknownKeyException('unknown config key');
Expand Down Expand Up @@ -721,7 +721,7 @@ private function setTypedValue(
int $type,
): bool {
$this->assertParams($app, $key);
$this->loadConfig($lazy);
$this->loadConfig(null, $lazy);

$sensitive = $this->isTyped(self::VALUE_SENSITIVE, $type);
$inserted = $refreshCache = false;
Expand Down Expand Up @@ -1176,29 +1176,30 @@ private function assertParams(string $app = '', string $configKey = '', bool $al
}
}

private function loadConfigAll(): void {
$this->loadConfig(null);
private function loadConfigAll(?string $app = null): void {
$this->loadConfig($app, null);
}

/**
* Load normal config or config set as lazy loaded
*
* @param bool|null $lazy set to TRUE to load config set as lazy loaded, set to NULL to load all config
*/
private function loadConfig(?bool $lazy = false): void {
private function loadConfig(?string $app = null, ?bool $lazy = false): void {
if ($this->isLoaded($lazy)) {
return;
}

if (($lazy ?? true) !== false) { // if lazy is null or true, we debug log
$this->logger->debug('The loading of lazy AppConfig values have been requested', ['exception' => new \RuntimeException('ignorable exception')]);
// if lazy is null or true, we debug log
if (($lazy ?? true) !== false && $app !== null) {
$this->logger->debug('The loading of lazy AppConfig values have been triggered by app "' . $app . '"', ['exception' => new \RuntimeException($app)]);
}

$qb = $this->connection->getQueryBuilder();
$qb->from('appconfig');

/**
* The use of $this->>migrationCompleted is only needed to manage the
* The use of $this->migrationCompleted is only needed to manage the
* database during the upgrading process to nc29.
*/
if (!$this->migrationCompleted) {
Expand Down Expand Up @@ -1301,7 +1302,7 @@ private function setAsLoaded(?bool $lazy): void {
* not exist the default value will be returned
*/
public function getValue($app, $key, $default = null) {
$this->loadConfig();
$this->loadConfig($app);

return $this->fastCache[$app][$key] ?? $default;
}
Expand Down

0 comments on commit 09f98b5

Please sign in to comment.