aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2024-01-10 08:57:36 -0100
committerMaxence Lange (Rebase PR Action) <maxence@artificial-owl.com>2024-01-11 15:46:48 +0000
commitc26110cbec87adc0d02976a9dfc83df74e295a0f (patch)
treea82d512160e469035a1015614b47f97d819db559 /core
parent10b9b20da50f74e3f3f04ce920aed0240e092cf2 (diff)
downloadnextcloud-server-c26110cbec87adc0d02976a9dfc83df74e295a0f.tar.gz
nextcloud-server-c26110cbec87adc0d02976a9dfc83df74e295a0f.zip
better users cycle
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'core')
-rw-r--r--core/BackgroundJobs/GenerateMetadataJob.php52
1 files changed, 26 insertions, 26 deletions
diff --git a/core/BackgroundJobs/GenerateMetadataJob.php b/core/BackgroundJobs/GenerateMetadataJob.php
index 393545b097d..65a687649b8 100644
--- a/core/BackgroundJobs/GenerateMetadataJob.php
+++ b/core/BackgroundJobs/GenerateMetadataJob.php
@@ -30,6 +30,7 @@ use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
+use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IConfig;
use OCP\IUserManager;
@@ -53,38 +54,33 @@ class GenerateMetadataJob extends TimedJob {
protected function run(mixed $argument): void {
$users = $this->userManager->search('');
- $lastMappedUser = $this->config->getAppValue('core', 'metadataGenerationLastHandledUser', '');
+ $lastHandledUser = $this->config->getAppValue('core', 'metadataGenerationLastHandledUser', '');
- if ($lastMappedUser === '') {
- $user = array_key_first($users);
- if ($user === null) {
- return;
- }
-
- $lastMappedUser = $users[$user]->getUID();
- }
-
- $startTime = null;
+ // we'll only start timer once we have found a valid user to handle
+ // meaning NOW if we have not handled any user from a previous run
+ $startTime = ($lastHandledUser === '') ? time() : null;
foreach ($users as $user) {
+ $userId = $user->getUID();
+
+ // if we already handled a previous run, we start timer only when we face the last handled user
if ($startTime === null) {
- // Skip all user before lastMappedUser.
- if ($lastMappedUser !== $user->getUID()) {
- continue;
+ if ($userId === $lastHandledUser) {
+ $startTime = time();
}
-
- $startTime = time();
+ continue;
}
+ $this->config->setAppValue('core', 'metadataGenerationLastHandledUser', $userId);
+ $this->scanFilesForUser($user->getUID());
+
// Stop if execution time is more than one hour.
- if (time() - $startTime > 60 * 60) {
+ if (time() - $startTime > 3600) {
return;
}
-
- $this->scanFilesForUser($user->getUID());
- $this->config->setAppValue('core', 'metadataGenerationLastHandledUser', $user->getUID());
}
$this->jobList->remove(GenerateMetadataJob::class);
+ $this->config->deleteAppValue('core', 'metadataGenerationLastHandledUser');
}
private function scanFilesForUser(string $userId): void {
@@ -105,12 +101,16 @@ class GenerateMetadataJob extends TimedJob {
}
try {
- $this->filesMetadataManager->refreshMetadata(
- $node,
- IFilesMetadataManager::PROCESS_LIVE | IFilesMetadataManager::PROCESS_BACKGROUND
- );
- } catch (\Throwable $ex) {
- $this->logger->warning("Error while generating metadata for fileid ".$node->getId(), ['exception' => $ex]);
+ $this->filesMetadataManager->getMetadata($node->getId(), false);
+ } catch (FilesMetadataNotFoundException) {
+ try {
+ $this->filesMetadataManager->refreshMetadata(
+ $node,
+ IFilesMetadataManager::PROCESS_LIVE | IFilesMetadataManager::PROCESS_BACKGROUND
+ );
+ } catch (\Throwable $ex) {
+ $this->logger->warning("Error while generating metadata for fileid " . $node->getId(), ['exception' => $ex]);
+ }
}
}
}