From a5e06e5edb4f14b7fb20e55ab4fce689963ca6b3 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Wed, 8 Nov 2023 20:18:02 +0530 Subject: [PATCH 1/3] add deleteSources function Signed-off-by: Anupam Kumar --- lib/Service/LangRopeService.php | 20 +++++++++++++++++++- lib/Service/ScanService.php | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Service/LangRopeService.php b/lib/Service/LangRopeService.php index c0cdb14..cf0e968 100644 --- a/lib/Service/LangRopeService.php +++ b/lib/Service/LangRopeService.php @@ -46,7 +46,25 @@ private function getExApp() { return $exApp; } - public function indexSources(string $userId, array $sources): void { + public function deleteSources(string $userId, string ...$sourceNames): void { + if (count($sourceNames) === 0) { + return; + } + + $params = [ + 'userId' => $userId, + 'sourceNames' => $sourceNames, + ]; + + $exApp = $this->getExApp(); + if ($exApp === null) { + return; + } + $this->requestToExApp($userId, $exApp, '/deleteSources', 'POST', $params); + } + + // variable number of args to type check array $sources + public function indexSources(string $userId, Source ...$sources): void { if (count($sources) === 0) { return; } diff --git a/lib/Service/ScanService.php b/lib/Service/ScanService.php index 2903a57..c9ea0fe 100644 --- a/lib/Service/ScanService.php +++ b/lib/Service/ScanService.php @@ -96,6 +96,6 @@ public function scanDirectory(string $userId, array $mimeTypeFilter, Folder $dir } public function indexSources(string $userId, array $sources): void { - $this->langRopeService->indexSources($userId, $sources); + $this->langRopeService->indexSources($userId, ...$sources); } } From 0adca2327bf88f6ed3de4162e4fd27a94109555e Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 9 Nov 2023 10:19:39 +0100 Subject: [PATCH 2/3] fix: revert LangRopeService API change --- lib/Service/LangRopeService.php | 15 ++++++++++++--- lib/Service/ScanService.php | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Service/LangRopeService.php b/lib/Service/LangRopeService.php index cf0e968..eda88b6 100644 --- a/lib/Service/LangRopeService.php +++ b/lib/Service/LangRopeService.php @@ -46,7 +46,12 @@ private function getExApp() { return $exApp; } - public function deleteSources(string $userId, string ...$sourceNames): void { + /** + * @param string $userId + * @param Source[] $sourceNames + * @return void + */ + public function deleteSources(string $userId, array $sourceNames): void { if (count($sourceNames) === 0) { return; } @@ -63,8 +68,12 @@ public function deleteSources(string $userId, string ...$sourceNames): void { $this->requestToExApp($userId, $exApp, '/deleteSources', 'POST', $params); } - // variable number of args to type check array $sources - public function indexSources(string $userId, Source ...$sources): void { + /** + * @param string $userId + * @param Source[] $sources + * @return void + */ + public function indexSources(string $userId, array $sources): void { if (count($sources) === 0) { return; } diff --git a/lib/Service/ScanService.php b/lib/Service/ScanService.php index c9ea0fe..2903a57 100644 --- a/lib/Service/ScanService.php +++ b/lib/Service/ScanService.php @@ -96,6 +96,6 @@ public function scanDirectory(string $userId, array $mimeTypeFilter, Folder $dir } public function indexSources(string $userId, array $sources): void { - $this->langRopeService->indexSources($userId, ...$sources); + $this->langRopeService->indexSources($userId, $sources); } } From 2ed09fb48ac1e50bafb79d5402dd7c2ed722b920 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Thu, 9 Nov 2023 10:28:54 +0100 Subject: [PATCH 3/3] fix: remove files from queue after indexing --- lib/BackgroundJobs/IndexerJob.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/BackgroundJobs/IndexerJob.php b/lib/BackgroundJobs/IndexerJob.php index 3c83d94..d24fb0d 100644 --- a/lib/BackgroundJobs/IndexerJob.php +++ b/lib/BackgroundJobs/IndexerJob.php @@ -136,6 +136,11 @@ protected function index(array $files): void { } $this->langRopeService->indexSources($userId, [$source]); } + try { + $this->queue->removeFromQueue($queueFile); + } catch (Exception $e) { + $this->logger->error('Could not remove file from queue', ['exception' => $e]); + } } } }