Skip to content

Commit f00aceb

Browse files
committed
fix(files_metadata): Don't run generation job on every upgrade
Signed-off-by: Louis Chemineau <[email protected]>
1 parent bb1f27f commit f00aceb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

core/BackgroundJobs/GenerateMetadataJob.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
use OCP\Files\IRootFolder;
1616
use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
1717
use OCP\FilesMetadata\IFilesMetadataManager;
18-
use OCP\IConfig;
18+
use OCP\IAppConfig;
1919
use OCP\IUserManager;
2020
use Psr\Log\LoggerInterface;
2121

2222
class GenerateMetadataJob extends TimedJob {
2323
public function __construct(
2424
ITimeFactory $time,
25-
private IConfig $config,
25+
private IAppConfig $appConfig,
2626
private IRootFolder $rootFolder,
2727
private IUserManager $userManager,
2828
private IFilesMetadataManager $filesMetadataManager,
@@ -36,8 +36,13 @@ public function __construct(
3636
}
3737

3838
protected function run(mixed $argument): void {
39+
if ($this->appConfig->getValueBool('core', 'metadataGenerationDone', false)) {
40+
return;
41+
}
42+
43+
$lastHandledUser = $this->appConfig->getValueString('core', 'metadataGenerationLastHandledUser', '');
44+
3945
$users = $this->userManager->search('');
40-
$lastHandledUser = $this->config->getAppValue('core', 'metadataGenerationLastHandledUser', '');
4146

4247
// we'll only start timer once we have found a valid user to handle
4348
// meaning NOW if we have not handled any user from a previous run
@@ -53,7 +58,7 @@ protected function run(mixed $argument): void {
5358
continue;
5459
}
5560

56-
$this->config->setAppValue('core', 'metadataGenerationLastHandledUser', $userId);
61+
$this->appConfig->setValueString('core', 'metadataGenerationLastHandledUser', $userId);
5762
$this->scanFilesForUser($user->getUID());
5863

5964
// Stop if execution time is more than one hour.
@@ -62,8 +67,8 @@ protected function run(mixed $argument): void {
6267
}
6368
}
6469

65-
$this->jobList->remove(GenerateMetadataJob::class);
66-
$this->config->deleteAppValue('core', 'metadataGenerationLastHandledUser');
70+
$this->appConfig->deleteKey('core', 'metadataGenerationLastHandledUser');
71+
$this->appConfig->setValueBool('core', 'metadataGenerationDone', true);
6772
}
6873

6974
private function scanFilesForUser(string $userId): void {

0 commit comments

Comments
 (0)