Skip to content

Commit

Permalink
lazy AppConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Dec 7, 2023
1 parent 4a9f998 commit f6b1250
Show file tree
Hide file tree
Showing 17 changed files with 1,401 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function getKeys(string $app): DataResponse {
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN);
}
return new DataResponse([
'data' => $this->config->getAppKeys($app),
'data' => $this->appConfig->getKeys($app),
]);
}

Expand Down
16 changes: 5 additions & 11 deletions core/Command/Config/ListConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
break;

case 'all':
$apps = $this->appConfig->getApps();
$apps = $this->appConfig->getApps(true);
$configs = [
'system' => $this->getSystemConfigs($noSensitiveValues),
'apps' => [],
Expand All @@ -91,9 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

default:
$configs = [
'apps' => [
$app => $this->getAppConfigs($app, $noSensitiveValues),
],
'apps' => [$app => $this->getAppConfigs($app, $noSensitiveValues)],
];
}

Expand All @@ -107,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
* @param bool $noSensitiveValues
* @return array
*/
protected function getSystemConfigs($noSensitiveValues) {
protected function getSystemConfigs(bool $noSensitiveValues): array {
$keys = $this->systemConfig->getKeys();

$configs = [];
Expand All @@ -133,12 +131,8 @@ protected function getSystemConfigs($noSensitiveValues) {
* @param bool $noSensitiveValues
* @return array
*/
protected function getAppConfigs($app, $noSensitiveValues) {
if ($noSensitiveValues) {
return $this->appConfig->getFilteredValues($app, false);
} else {
return $this->appConfig->getValues($app, false);
}
protected function getAppConfigs(string $app, bool $noSensitiveValues) {
return $this->appConfig->getAllValues($app, filtered: $noSensitiveValues);
}

/**
Expand Down
13 changes: 2 additions & 11 deletions core/Command/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

use OC\Console\TimestampFormatter;
use OC\DB\MigratorExecuteSqlEvent;
use OC\Installer;
use OC\Repair\Events\RepairAdvanceEvent;
use OC\Repair\Events\RepairErrorEvent;
use OC\Repair\Events\RepairFinishEvent;
Expand All @@ -48,7 +47,6 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\Util;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -63,9 +61,7 @@ class Upgrade extends Command {
public const ERROR_FAILURE = 5;

public function __construct(
private IConfig $config,
private LoggerInterface $logger,
private Installer $installer,
private IConfig $config
) {
parent::__construct();
}
Expand All @@ -91,12 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$self = $this;
$updater = new Updater(
$this->config,
\OC::$server->getIntegrityCodeChecker(),
$this->logger,
$this->installer
);
$updater = \OCP\Server::get(Updater::class);

/** @var IEventDispatcher $dispatcher */
$dispatcher = \OC::$server->get(IEventDispatcher::class);
Expand Down
62 changes: 62 additions & 0 deletions core/Migrations/Version29000Date20231126110901.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);
/**
* @copyright 2023 Maxence Lange <[email protected]>
*
* @author Maxence Lange <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OC\Core\Migrations;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

// Create new field in appconfig for the new IAppConfig API, including lazy grouping.
class Version29000Date20231126110901 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if (!$schema->hasTable('appconfig')) {
return null;
}

$table = $schema->getTable('appconfig');
if ($table->hasColumn('lazy_group')) {
return null;
}

$table->addColumn('lazy_group', Types::STRING, ['length' => 32, 'default' => '']);
$table->addColumn('sensitive', Types::SMALLINT, ['length' => 1, 'default' => '0']);

if ($table->hasIndex('appconfig_config_key_index')) {
$table->dropIndex('appconfig_config_key_index');
}

$table->addIndex(['lazy_group'], 'ac_lazy_i');
$table->addIndex(['appid', 'lazy_group'], 'ac_app_lazy_i');
$table->addIndex(['appid', 'lazy_group', 'configkey'], 'ac_app_lazy_key_i');

return $schema;
}
}
6 changes: 5 additions & 1 deletion core/ajax/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
use OC\Repair\Events\RepairWarningEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IEventSource;
use OCP\IEventSourceFactory;
use OCP\IL10N;
use OCP\ILogger;
use OCP\L10N\IFactory;
use OCP\Server;

if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
@set_time_limit(0);
Expand Down Expand Up @@ -112,9 +115,10 @@ public function handleRepairFeedback(Event $event): void {
\OC_User::setIncognitoMode(true);

$logger = \OC::$server->get(\Psr\Log\LoggerInterface::class);
$config = \OC::$server->getConfig();
$config = Server::get(IConfig::class);
$updater = new \OC\Updater(
$config,
Server::get(IAppConfig::class),
\OC::$server->getIntegrityCodeChecker(),
$logger,
\OC::$server->query(\OC\Installer::class)
Expand Down
4 changes: 2 additions & 2 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
$application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
$application->add(\OCP\Server::get(\OC\Core\Command\Config\ListConfigs::class));
$application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
Expand Down Expand Up @@ -170,7 +170,7 @@
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));

$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class)));
$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Maintenance\Repair(
new \OC\Repair([], \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)),
\OC::$server->getConfig(),
Expand Down
11 changes: 8 additions & 3 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
* Class to combine all the configuration options ownCloud offers
*/
class AllConfig implements IConfig {
private SystemConfig $systemConfig;
private ?IDBConnection $connection = null;

/**
Expand All @@ -68,9 +67,10 @@ class AllConfig implements IConfig {
*/
private CappedMemoryCache $userCache;

public function __construct(SystemConfig $systemConfig) {
public function __construct(
private SystemConfig $systemConfig
) {
$this->userCache = new CappedMemoryCache();
$this->systemConfig = $systemConfig;
}

/**
Expand Down Expand Up @@ -190,6 +190,7 @@ public function deleteSystemValue($key) {
*
* @param string $appName the appName that we stored the value under
* @return string[] the keys stored for the app
* @deprecated - load IAppConfig directly
*/
public function getAppKeys($appName) {
return \OC::$server->get(AppConfig::class)->getKeys($appName);
Expand All @@ -201,6 +202,7 @@ public function getAppKeys($appName) {
* @param string $appName the appName that we want to store the value under
* @param string $key the key of the value, under which will be saved
* @param string|float|int $value the value that should be stored
* @deprecated - load IAppConfig directly
*/
public function setAppValue($appName, $key, $value) {
\OC::$server->get(AppConfig::class)->setValue($appName, $key, $value);
Expand All @@ -213,6 +215,7 @@ public function setAppValue($appName, $key, $value) {
* @param string $key the key of the value, under which it was saved
* @param string $default the default value to be returned if the value isn't set
* @return string the saved value
* @deprecated - load IAppConfig directly
*/
public function getAppValue($appName, $key, $default = '') {
return \OC::$server->get(AppConfig::class)->getValue($appName, $key, $default);
Expand All @@ -223,6 +226,7 @@ public function getAppValue($appName, $key, $default = '') {
*
* @param string $appName the appName that we stored the value under
* @param string $key the key of the value, under which it was saved
* @deprecated - load IAppConfig directly
*/
public function deleteAppValue($appName, $key) {
\OC::$server->get(AppConfig::class)->deleteKey($appName, $key);
Expand All @@ -232,6 +236,7 @@ public function deleteAppValue($appName, $key) {
* Removes all keys in appconfig belonging to the app
*
* @param string $appName the appName the configs are stored under
* @deprecated - load IAppConfig directly
*/
public function deleteAppValues($appName) {
\OC::$server->get(AppConfig::class)->deleteApp($appName);
Expand Down
Loading

0 comments on commit f6b1250

Please sign in to comment.