Skip to content
Open
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
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Setup background job workers as described here: https://docs.nextcloud.com/serve
Note:
Refer to the [Context Chat Backend's readme](https://github.com/nextcloud/context_chat_backend/?tab=readme-ov-file) and the [AppAPI's documentation](https://cloud-py-api.github.io/app_api/) for help with setup of AppAPI's deploy daemon.
]]></description>
<version>5.0.0</version>
<version>5.0.1</version>
<licence>agpl</licence>
<author>Julien Veyssier</author>
<author>Anupam Kumar</author>
Expand Down
6 changes: 0 additions & 6 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use OCP\Files\Events\Node\NodeRenamedEvent;
use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Events\NodeRemovedFromCache;
use OCP\IConfig;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\User\Events\UserDeletedEvent;
Expand Down Expand Up @@ -64,13 +63,8 @@ class Application extends App implements IBootstrap {
'text/org',
];

private IConfig $config;

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);

$container = $this->getContainer();
$this->config = $container->get(IConfig::class);
}

public function register(IRegistrationContext $context): void {
Expand Down
10 changes: 4 additions & 6 deletions lib/BackgroundJobs/ActionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
use OCA\ContextChat\Service\LangRopeService;
use OCA\ContextChat\Type\ActionType;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\Exception;
use OCP\IConfig;

class ActionJob extends TimedJob {
private const BATCH_SIZE = 1000;
Expand All @@ -28,23 +27,22 @@ public function __construct(
ITimeFactory $timeFactory,
private LangRopeService $networkService,
private QueueActionMapper $actionMapper,
private IJobList $jobList,
private Logger $logger,
private DiagnosticService $diagnosticService,
private IAppManager $appManager,
private IConfig $config,
private IAppConfig $appConfig,
) {
parent::__construct($timeFactory);
$this->setAllowParallelRuns(false);
$this->setInterval($this->getJobInterval());
}

private function getJobInterval(): int {
return intval($this->config->getAppValue('context_chat', 'action_job_interval', (string)(5 * 60))); // 5 minutes
return intval($this->appConfig->getAppValueString('action_job_interval', (string)(5 * 60), lazy: true)); // 5 minutes
}

protected function run($argument): void {
if (!$this->appManager->isInstalled('app_api')) {
if (!$this->appManager->isEnabledForAnyone('app_api')) {
$this->logger->warning('ActionJob is skipped as app_api is disabled');
return;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/BackgroundJobs/FileSystemListenerJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
use OCA\ContextChat\Service\FsEventService;
use OCA\ContextChat\Type\FsEventType;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\DB\Exception;
use OCP\Files\IRootFolder;
use OCP\IConfig;

class FileSystemListenerJob extends TimedJob {
private const BATCH_SIZE = 500;
Expand All @@ -40,19 +40,19 @@ public function __construct(
private IAppManager $appManager,
private FsEventService $fsEventService,
private IRootFolder $rootFolder,
private IConfig $config,
private IAppConfig $appConfig,
) {
parent::__construct($timeFactory);
$this->allowParallelRuns = false;
$this->setInterval($this->getJobInterval());
}

private function getJobInterval(): int {
return intval($this->config->getAppValue('context_chat', 'fs_listener_job_interval', (string)(5 * 60))); // 5 minutes
return intval($this->appConfig->getAppValueString('fs_listener_job_interval', (string)(5 * 60), lazy: true)); // 5 minutes
}

protected function run($argument): void {
if (!$this->appManager->isInstalled('app_api')) {
if (!$this->appManager->isEnabledForAnyone('app_api')) {
$this->logger->warning('FileSystemListenerJob is skipped as app_api is disabled');
return;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/BackgroundJobs/IndexerJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public function __construct(
* @throws \Throwable
*/
public function run($argument): void {
if (!$this->appManager->isInstalled('app_api')) {
if (!$this->appManager->isEnabledForAnyone('app_api')) {
$this->logger->warning('IndexerJob is skipped as app_api is disabled');
return;
}

$this->storageId = $argument['storageId'];
$this->rootId = $argument['rootId'];
if ($this->appConfig->getAppValue('auto_indexing', 'true') === 'false') {
if ($this->appConfig->getAppValueString('auto_indexing', 'true', lazy: true) === 'false') {
return;
}
$this->diagnosticService->sendJobTrigger(static::class, $this->getId());
Expand Down Expand Up @@ -149,19 +149,19 @@ public function run($argument): void {
}

protected function getBatchSize(): int {
return $this->appConfig->getAppValueInt('indexing_batch_size', self::DEFAULT_BATCH_SIZE);
return $this->appConfig->getAppValueInt('indexing_batch_size', self::DEFAULT_BATCH_SIZE, lazy: true);
}

protected function getMaxIndexingTime(): int {
return $this->appConfig->getAppValueInt('indexing_max_time', self::DEFAULT_MAX_INDEXING_TIME);
return $this->appConfig->getAppValueInt('indexing_max_time', self::DEFAULT_MAX_INDEXING_TIME, lazy: true);
}

protected function getJobInterval(): int {
return $this->appConfig->getAppValueInt('indexing_job_interval', self::DEFAULT_JOB_INTERVAL);
return $this->appConfig->getAppValueInt('indexing_job_interval', self::DEFAULT_JOB_INTERVAL, lazy: true);
}

protected function getMaxSize(): float {
return (float)$this->appConfig->getAppValueInt('indexing_max_size', Application::CC_MAX_SIZE);
return (float)$this->appConfig->getAppValueInt('indexing_max_size', Application::CC_MAX_SIZE, lazy: true);
}

/**
Expand Down Expand Up @@ -321,7 +321,7 @@ protected function index(array $files): void {
}

private function setInitialIndexCompletion(): void {
if ($this->appConfig->getAppValueInt('last_indexed_time', 0) !== 0) {
if ($this->appConfig->getAppValueInt('last_indexed_time', 0, lazy: true) !== 0) {
return;
}
try {
Expand All @@ -345,7 +345,7 @@ private function setInitialIndexCompletion(): void {
}

$this->logger->info('Initial index completion detected, setting last indexed time');
$this->appConfig->setAppValueInt('last_indexed_time', $this->timeFactory->getTime(), false);
$this->appConfig->setAppValueInt('last_indexed_time', $this->timeFactory->getTime(), lazy: true);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions lib/BackgroundJobs/InitialContentImportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
namespace OCA\ContextChat\BackgroundJobs;

use OCA\ContextChat\Logger;
use OCA\ContextChat\Public\IContentProvider;
use OCA\ContextChat\Public\IContentProvider as OCAIContentProvider;
use OCA\ContextChat\Service\ProviderConfigService;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\ContextChat\IContentProvider as OCPIContentProvider;
use OCP\IUserManager;
use OCP\Server;
use Psr\Container\ContainerExceptionInterface;
Expand All @@ -33,7 +34,7 @@ public function __construct(
}

/**
* @param class-string<IContentProvider> $argument Provider class name
* @param class-string<OCAIContentProvider|OCPIContentProvider> $argument Provider class name
* @return void
*/
protected function run($argument): void {
Expand All @@ -42,14 +43,15 @@ protected function run($argument): void {
}

try {
/** @var IContentProvider */
/** @var OCAIContentProvider|OCPIContentProvider */
$providerObj = Server::get($argument);
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
$this->logger->warning('[InitialContentImportJob] Could not run initial import for content provider', ['exception' => $e]);
return;
}

if (!$this->appManager->isEnabledForUser($providerObj->getAppId())) {
$user = $this->userMan->get($this->userId ?? '');
if (!$this->appManager->isEnabledForUser($providerObj->getAppId(), $user)) {
$this->logger->info('[InitialContentImportJob] App is not enabled for user, skipping content import', ['appId' => $providerObj->getAppId()]);
return;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/BackgroundJobs/RotateLogsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OCA\ContextChat\BackgroundJobs;

use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IConfig;
Expand All @@ -18,15 +19,16 @@ class RotateLogsJob extends TimedJob {
public function __construct(
ITimeFactory $time,
private IConfig $config,
private IAppConfig $appConfig,
) {
parent::__construct($time);

$this->setInterval(60 * 60 * 3);
$this->setInterval(60 * 60 * 3); // every 3 hours
}

protected function run($argument): void {
$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/context_chat.log';
$this->filePath = $this->config->getAppValue('context_chat', 'logfile', $default);
$this->filePath = $this->appConfig->getAppValueString('logfile', $default, lazy: true);

$this->maxSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);

Expand Down
4 changes: 2 additions & 2 deletions lib/BackgroundJobs/SchedulerJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __construct(
* @throws Exception
*/
protected function run($argument): void {
$this->appConfig->setAppValueString('indexed_files_count', (string)0);
$this->appConfig->setAppValueInt('last_indexed_time', 0);
$this->appConfig->setAppValueString('indexed_files_count', (string)0, lazy: true);
$this->appConfig->setAppValueInt('last_indexed_time', 0, lazy: true);
foreach ($this->storageService->getMounts() as $mount) {
$this->logger->debug('Scheduling StorageCrawlJob storage_id=' . $mount['storage_id'] . ' root_id=' . $mount['root_id' ] . 'override_root=' . $mount['overridden_root']);
$this->jobList->add(StorageCrawlJob::class, [
Expand Down
7 changes: 3 additions & 4 deletions lib/BackgroundJobs/StorageCrawlJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@

namespace OCA\ContextChat\BackgroundJobs;

use OCA\ContextChat\AppInfo\Application;
use OCA\ContextChat\Db\QueueFile;
use OCA\ContextChat\Logger;
use OCA\ContextChat\Service\DiagnosticService;
use OCA\ContextChat\Service\QueueService;
use OCA\ContextChat\Service\StorageService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\QueuedJob;
use OCP\DB\Exception;
use OCP\IAppConfig;

class StorageCrawlJob extends QueuedJob {
public const BATCH_SIZE = 2000;
Expand Down Expand Up @@ -91,7 +90,7 @@ protected function run($argument): void {

if ($lastSuccessfulFileId !== -1) {
// the last job to set this value will win
$this->appConfig->setValueInt(Application::APP_ID, 'last_indexed_file_id', $lastSuccessfulFileId);
$this->appConfig->setAppValueInt('last_indexed_file_id', $lastSuccessfulFileId, lazy: true);
}
}
} finally {
Expand All @@ -100,6 +99,6 @@ protected function run($argument): void {
}

protected function getJobInterval(): int {
return $this->appConfig->getValueInt(Application::APP_ID, 'crawl_job_interval', self::DEFAULT_JOB_INTERVAL);
return $this->appConfig->getAppValueInt('crawl_job_interval', self::DEFAULT_JOB_INTERVAL, lazy: true);
}
}
4 changes: 2 additions & 2 deletions lib/BackgroundJobs/SubmitContentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
* @return void
*/
protected function run($argument): void {
if (!$this->appManager->isInstalled('app_api')) {
if (!$this->appManager->isEnabledForAnyone('app_api')) {
$this->logger->warning('SubmitContentJob is skipped as app_api is disabled');
return;
}
Expand All @@ -63,7 +63,7 @@ protected function run($argument): void {
return;
}

$maxSize = $this->appConfig->getAppValueInt('indexing_max_size', Application::CC_MAX_SIZE);
$maxSize = $this->appConfig->getAppValueInt('indexing_max_size', Application::CC_MAX_SIZE, lazy: true);

if (empty($entities)) {
return;
Expand Down
8 changes: 4 additions & 4 deletions lib/Command/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ protected function configure() {

protected function execute(InputInterface $input, OutputInterface $output): int {
$output->writeln('ContextChat statistics:');
if ($this->appConfig->getAppValueInt('last_indexed_time', 0) === 0) {
if ($this->appConfig->getAppValueInt('last_indexed_time', 0, lazy: true) === 0) {
$output->writeln('The indexing is not complete yet.');
} else {
$installedTime = $this->appConfig->getAppValueInt('installed_time', 0);
$lastIndexedTime = $this->appConfig->getAppValueInt('last_indexed_time', 0);
$installedTime = $this->appConfig->getAppValueInt('installed_time', 0, lazy: true);
$lastIndexedTime = $this->appConfig->getAppValueInt('last_indexed_time', 0, lazy: true);
$indexTime = $lastIndexedTime - $installedTime;

$output->writeln('Installed time: ' . (new \DateTime('@' . $installedTime))->format('Y-m-d H:i') . ' UTC');
Expand All @@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$queuedDocumentsCount = $this->contentQueue->count();
$output->writeln('Queued documents (without files):' . var_export($queuedDocumentsCount, true));

$indexFilesCount = Util::numericToNumber($this->appConfig->getAppValueString('indexed_files_count', '0'));
$indexFilesCount = Util::numericToNumber(intval($this->appConfig->getAppValueString('indexed_files_count', '0', lazy: true)));
$output->writeln('Files successfully sent to backend: ' . strval($indexFilesCount));

$indexedDocumentsCount = $this->langRopeService->getIndexedDocumentsCounts();
Expand Down
13 changes: 7 additions & 6 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

namespace OCA\ContextChat\Controller;

use OCA\ContextChat\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;

use OCP\AppFramework\Services\IAppConfig;
use OCP\IRequest;
use OCP\PreConditionNotMetException;

Expand All @@ -21,7 +19,7 @@ class ConfigController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private IConfig $config,
private IAppConfig $appConfig,
private ?string $userId,
) {
parent::__construct($appName, $request);
Expand All @@ -36,8 +34,11 @@ public function __construct(
*/
#[NoAdminRequired]
public function setConfig(array $values): DataResponse {
if ($this->userId === null) {
throw new PreConditionNotMetException('User must be logged in to set user config values');
}
foreach ($values as $key => $value) {
$this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
$this->appConfig->setUserValue($this->userId, $key, $value);
}
return new DataResponse(1);
}
Expand All @@ -50,7 +51,7 @@ public function setConfig(array $values): DataResponse {
*/
public function setAdminConfig(array $values): DataResponse {
foreach ($values as $key => $value) {
$this->config->setAppValue(Application::APP_ID, $key, $value);
$this->appConfig->setAppValueString($key, $value, lazy: true);
}
return new DataResponse(1);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/Listener/ShareListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
use OCA\ContextChat\Service\StorageService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IGroupManager;
use OCP\Share\Events\ShareCreatedEvent;
Expand All @@ -37,7 +35,6 @@ public function __construct(
private Logger $logger,
private StorageService $storageService,
private IManager $shareManager,
private IRootFolder $rootFolder,
private ActionScheduler $actionService,
private IGroupManager $groupManager,
) {
Expand Down
Loading
Loading