Skip to content

Commit 96decee

Browse files
committed
lazy AppConfig
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent f6b49b1 commit 96decee

File tree

17 files changed

+1334
-363
lines changed

17 files changed

+1334
-363
lines changed

apps/provisioning_api/lib/Controller/AppConfigController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getKeys(string $app): DataResponse {
113113
return new DataResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_FORBIDDEN);
114114
}
115115
return new DataResponse([
116-
'data' => $this->config->getAppKeys($app),
116+
'data' => $this->appConfig->getKeys($app),
117117
]);
118118
}
119119

core/Command/Config/ListConfigs.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7979
break;
8080

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

9292
default:
9393
$configs = [
94-
'apps' => [
95-
$app => $this->getAppConfigs($app, $noSensitiveValues),
96-
],
94+
'apps' => [$app => $this->getAppConfigs($app, $noSensitiveValues)],
9795
];
9896
}
9997

@@ -107,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
107105
* @param bool $noSensitiveValues
108106
* @return array
109107
*/
110-
protected function getSystemConfigs($noSensitiveValues) {
108+
protected function getSystemConfigs(bool $noSensitiveValues): array {
111109
$keys = $this->systemConfig->getKeys();
112110

113111
$configs = [];
@@ -133,9 +131,10 @@ protected function getSystemConfigs($noSensitiveValues) {
133131
* @param bool $noSensitiveValues
134132
* @return array
135133
*/
136-
protected function getAppConfigs($app, $noSensitiveValues) {
134+
protected function getAppConfigs(string $app, bool $noSensitiveValues) {
135+
// return $this->appConfig->getAllValues($app, filtered: $noSensitiveValues);
137136
if ($noSensitiveValues) {
138-
return $this->appConfig->getFilteredValues($app, false);
137+
return $this->appConfig->getFilteredValues($app);
139138
} else {
140139
return $this->appConfig->getValues($app, false);
141140
}

core/Command/Upgrade.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use OC\Updater;
4747
use OCP\EventDispatcher\Event;
4848
use OCP\EventDispatcher\IEventDispatcher;
49+
use OCP\IAppConfig;
4950
use OCP\IConfig;
5051
use OCP\Util;
5152
use Psr\Log\LoggerInterface;
@@ -63,9 +64,7 @@ class Upgrade extends Command {
6364
public const ERROR_FAILURE = 5;
6465

6566
public function __construct(
66-
private IConfig $config,
67-
private LoggerInterface $logger,
68-
private Installer $installer,
67+
private IConfig $config
6968
) {
7069
parent::__construct();
7170
}
@@ -91,12 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9190
}
9291

9392
$self = $this;
94-
$updater = new Updater(
95-
$this->config,
96-
\OC::$server->getIntegrityCodeChecker(),
97-
$this->logger,
98-
$this->installer
99-
);
93+
$updater = \OCP\Server::get(Updater::class);
10094

10195
/** @var IEventDispatcher $dispatcher */
10296
$dispatcher = \OC::$server->get(IEventDispatcher::class);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright 2023 Maxence Lange <maxence@artificial-owl.com>
6+
*
7+
* @author Maxence Lange <maxence@artificial-owl.com>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OC\Core\Migrations;
27+
28+
use Closure;
29+
use OCP\DB\ISchemaWrapper;
30+
use OCP\DB\Types;
31+
use OCP\Migration\IOutput;
32+
use OCP\Migration\SimpleMigrationStep;
33+
34+
// Create new field in appconfig for the new IAppConfig API, including lazy grouping.
35+
class Version29000Date20231126110901 extends SimpleMigrationStep {
36+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
37+
/** @var ISchemaWrapper $schema */
38+
$schema = $schemaClosure();
39+
40+
if (!$schema->hasTable('appconfig')) {
41+
return null;
42+
}
43+
44+
$table = $schema->getTable('appconfig');
45+
if ($table->hasColumn('lazy_group')) {
46+
return null;
47+
}
48+
49+
$table->addColumn('lazy_group', Types::STRING, ['length' => 32, 'default' => '']);
50+
$table->addColumn('sensitive', Types::SMALLINT, ['length' => 1, 'default' => '0']);
51+
52+
if ($table->hasIndex('appconfig_config_key_index')) {
53+
$table->dropIndex('appconfig_config_key_index');
54+
}
55+
56+
$table->addIndex(['lazy_group'], 'ac_lazy_i');
57+
$table->addIndex(['appid', 'lazy_group'], 'ac_app_lazy_i');
58+
$table->addIndex(['appid', 'lazy_group', 'configkey'], 'ac_app_lazy_key_i');
59+
60+
return $schema;
61+
}
62+
}

core/ajax/update.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@
4040
use OC\Repair\Events\RepairWarningEvent;
4141
use OCP\EventDispatcher\Event;
4242
use OCP\EventDispatcher\IEventDispatcher;
43+
use OCP\IAppConfig;
44+
use OCP\IConfig;
4345
use OCP\IEventSource;
4446
use OCP\IEventSourceFactory;
4547
use OCP\IL10N;
4648
use OCP\ILogger;
4749
use OCP\L10N\IFactory;
50+
use OCP\Server;
4851

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

114117
$logger = \OC::$server->get(\Psr\Log\LoggerInterface::class);
115-
$config = \OC::$server->getConfig();
118+
$config = Server::get(IConfig::class);
116119
$updater = new \OC\Updater(
117120
$config,
121+
Server::get(IAppConfig::class),
118122
\OC::$server->getIntegrityCodeChecker(),
119123
$logger,
120124
\OC::$server->query(\OC\Installer::class)

core/register_command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
$application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
100100
$application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
101101
$application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
102-
$application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
102+
$application->add(\OCP\Server::get(\OC\Core\Command\Config\ListConfigs::class));
103103
$application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
104104
$application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
105105
$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));

lib/private/AllConfig.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
* Class to combine all the configuration options ownCloud offers
4444
*/
4545
class AllConfig implements IConfig {
46-
private SystemConfig $systemConfig;
4746
private ?IDBConnection $connection = null;
4847

4948
/**
@@ -68,9 +67,10 @@ class AllConfig implements IConfig {
6867
*/
6968
private CappedMemoryCache $userCache;
7069

71-
public function __construct(SystemConfig $systemConfig) {
70+
public function __construct(
71+
private SystemConfig $systemConfig
72+
) {
7273
$this->userCache = new CappedMemoryCache();
73-
$this->systemConfig = $systemConfig;
7474
}
7575

7676
/**
@@ -190,6 +190,7 @@ public function deleteSystemValue($key) {
190190
*
191191
* @param string $appName the appName that we stored the value under
192192
* @return string[] the keys stored for the app
193+
* @deprecated - load IAppConfig directly
193194
*/
194195
public function getAppKeys($appName) {
195196
return \OC::$server->get(AppConfig::class)->getKeys($appName);
@@ -201,6 +202,7 @@ public function getAppKeys($appName) {
201202
* @param string $appName the appName that we want to store the value under
202203
* @param string $key the key of the value, under which will be saved
203204
* @param string|float|int $value the value that should be stored
205+
* @deprecated - load IAppConfig directly
204206
*/
205207
public function setAppValue($appName, $key, $value) {
206208
\OC::$server->get(AppConfig::class)->setValue($appName, $key, $value);
@@ -213,6 +215,7 @@ public function setAppValue($appName, $key, $value) {
213215
* @param string $key the key of the value, under which it was saved
214216
* @param string $default the default value to be returned if the value isn't set
215217
* @return string the saved value
218+
* @deprecated - load IAppConfig directly
216219
*/
217220
public function getAppValue($appName, $key, $default = '') {
218221
return \OC::$server->get(AppConfig::class)->getValue($appName, $key, $default);
@@ -223,6 +226,7 @@ public function getAppValue($appName, $key, $default = '') {
223226
*
224227
* @param string $appName the appName that we stored the value under
225228
* @param string $key the key of the value, under which it was saved
229+
* @deprecated - load IAppConfig directly
226230
*/
227231
public function deleteAppValue($appName, $key) {
228232
\OC::$server->get(AppConfig::class)->deleteKey($appName, $key);
@@ -232,6 +236,7 @@ public function deleteAppValue($appName, $key) {
232236
* Removes all keys in appconfig belonging to the app
233237
*
234238
* @param string $appName the appName the configs are stored under
239+
* @deprecated - load IAppConfig directly
235240
*/
236241
public function deleteAppValues($appName) {
237242
\OC::$server->get(AppConfig::class)->deleteApp($appName);

0 commit comments

Comments
 (0)