mirror of
https://github.com/nextcloud/server.git
synced 2026-06-14 19:20:35 -04:00
feat(taskprocessing): load and store some config keys lazily
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
parent
2211390ca5
commit
2e3fa51132
5 changed files with 30 additions and 20 deletions
|
|
@ -12,20 +12,15 @@ use OCA\Settings\Settings\Admin\ArtificialIntelligence;
|
|||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\IRequest;
|
||||
|
||||
class AISettingsController extends Controller {
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(
|
||||
$appName,
|
||||
IRequest $request,
|
||||
private IConfig $config,
|
||||
private IAppConfig $appConfig,
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
|
@ -43,7 +38,7 @@ class AISettingsController extends Controller {
|
|||
if (!isset($settings[$key])) {
|
||||
continue;
|
||||
}
|
||||
$this->config->setAppValue('core', $key, json_encode($settings[$key]));
|
||||
$this->appConfig->setValueString('core', $key, json_encode($settings[$key]), lazy: in_array($key, \OCP\TaskProcessing\IManager::LAZY_CONFIG_KEYS, true));
|
||||
}
|
||||
|
||||
return new DataResponse();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace OCA\Settings\Settings\Admin;
|
|||
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\IConfig;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\Settings\IDelegatedSettings;
|
||||
use OCP\SpeechToText\ISpeechToTextManager;
|
||||
|
|
@ -28,7 +28,7 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
class ArtificialIntelligence implements IDelegatedSettings {
|
||||
public function __construct(
|
||||
private IConfig $config,
|
||||
private IAppConfig $appConfig,
|
||||
private IL10N $l,
|
||||
private IInitialState $initialState,
|
||||
private ITranslationManager $translationManager,
|
||||
|
|
@ -145,7 +145,7 @@ class ArtificialIntelligence implements IDelegatedSettings {
|
|||
];
|
||||
foreach ($settings as $key => $defaultValue) {
|
||||
$value = $defaultValue;
|
||||
$json = $this->config->getAppValue('core', $key, '');
|
||||
$json = $this->appConfig->getValueString('core', $key, '', lazy: in_array($key, \OCP\TaskProcessing\IManager::LAZY_CONFIG_KEYS, true));
|
||||
if ($json !== '') {
|
||||
try {
|
||||
$value = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
namespace OC\Core\Command\TaskProcessing;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCP\IConfig;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\TaskProcessing\IManager;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
|
@ -16,7 +16,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
class EnabledCommand extends Base {
|
||||
public function __construct(
|
||||
protected IManager $taskProcessingManager,
|
||||
private IConfig $config,
|
||||
private IAppConfig $appConfig,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ class EnabledCommand extends Base {
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$enabled = (bool)$input->getArgument('enabled');
|
||||
$taskType = $input->getArgument('task-type-id');
|
||||
$json = $this->config->getAppValue('core', 'ai.taskprocessing_type_preferences');
|
||||
$json = $this->appConfig->getValueString('core', 'ai.taskprocessing_type_preferences', lazy: true);
|
||||
try {
|
||||
if ($json === '') {
|
||||
$taskTypeSettings = [];
|
||||
|
|
@ -51,7 +51,7 @@ class EnabledCommand extends Base {
|
|||
|
||||
$taskTypeSettings[$taskType] = $enabled;
|
||||
|
||||
$this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', json_encode($taskTypeSettings));
|
||||
$this->appConfig->setValueString('core', 'ai.taskprocessing_type_preferences', json_encode($taskTypeSettings), lazy: true);
|
||||
$this->writeArrayInOutputFormat($input, $output, $taskTypeSettings);
|
||||
return 0;
|
||||
} catch (\JsonException $e) {
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ use OCP\Files\Node;
|
|||
use OCP\Files\NotPermittedException;
|
||||
use OCP\Files\SimpleFS\ISimpleFile;
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\ICache;
|
||||
use OCP\ICacheFactory;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\IUserManager;
|
||||
|
|
@ -92,7 +92,7 @@ class Manager implements IManager {
|
|||
private ?GetTaskProcessingProvidersEvent $eventResult = null;
|
||||
|
||||
public function __construct(
|
||||
private IConfig $config,
|
||||
private IAppConfig $appConfig,
|
||||
private Coordinator $coordinator,
|
||||
private IServerContainer $serverContainer,
|
||||
private LoggerInterface $logger,
|
||||
|
|
@ -630,7 +630,7 @@ class Manager implements IManager {
|
|||
*/
|
||||
private function _getTaskTypeSettings(): array {
|
||||
try {
|
||||
$json = $this->config->getAppValue('core', 'ai.taskprocessing_type_preferences', '');
|
||||
$json = $this->appConfig->getValueString('core', 'ai.taskprocessing_type_preferences', '', lazy: true);
|
||||
if ($json === '') {
|
||||
return [];
|
||||
}
|
||||
|
|
@ -788,7 +788,11 @@ class Manager implements IManager {
|
|||
if ($this->preferences === null) {
|
||||
$this->preferences = $this->distributedCache->get('ai.taskprocessing_provider_preferences');
|
||||
if ($this->preferences === null) {
|
||||
$this->preferences = json_decode($this->config->getAppValue('core', 'ai.taskprocessing_provider_preferences', 'null'), associative: true, flags: JSON_THROW_ON_ERROR);
|
||||
$this->preferences = json_decode(
|
||||
$this->appConfig->getValueString('core', 'ai.taskprocessing_provider_preferences', 'null', lazy: true),
|
||||
associative: true,
|
||||
flags: JSON_THROW_ON_ERROR,
|
||||
);
|
||||
$this->distributedCache->set('ai.taskprocessing_provider_preferences', $this->preferences, 60 * 3);
|
||||
}
|
||||
}
|
||||
|
|
@ -889,7 +893,7 @@ class Manager implements IManager {
|
|||
$user = $this->userManager->get($userId);
|
||||
}
|
||||
|
||||
$guestsAllowed = $this->config->getAppValue('core', 'ai.taskprocessing_guests', 'false');
|
||||
$guestsAllowed = $this->appConfig->getValueString('core', 'ai.taskprocessing_guests', 'false');
|
||||
if ($guestsAllowed == 'true' || !class_exists(\OCA\Guests\UserBackend::class) || !($user->getBackend() instanceof \OCA\Guests\UserBackend)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,17 @@ use OCP\TaskProcessing\Exception\ValidationException;
|
|||
* @since 30.0.0
|
||||
*/
|
||||
interface IManager {
|
||||
|
||||
/**
|
||||
* Task processing config keys that can be stored and loaded lazily
|
||||
*
|
||||
* @since 32.0.0
|
||||
*/
|
||||
public const LAZY_CONFIG_KEYS = [
|
||||
'ai.taskprocessing_type_preferences',
|
||||
'ai.taskprocessing_provider_preferences',
|
||||
];
|
||||
|
||||
/**
|
||||
* @since 30.0.0
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue