Skip to content

Commit

Permalink
Merge pull request #66 from nextcloud/fix/indexer-inflation
Browse files Browse the repository at this point in the history
Stop inflation of Indexer jobs
  • Loading branch information
marcelklehr authored Oct 21, 2024
2 parents e094fdf + 921cb07 commit c996ecf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/BackgroundJobs/IndexerJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

class IndexerJob extends TimedJob {

public const DEFAULT_MAX_INDEXING_TIME = 5 * 60;

public function __construct(
ITimeFactory $time,
private LoggerInterface $logger,
Expand All @@ -42,7 +44,7 @@ public function __construct(
private IAppConfig $appConfig,
) {
parent::__construct($time);
$this->setInterval(60 * 5);
$this->setInterval($this->getMaxIndexingTime());
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
}

Expand Down Expand Up @@ -111,13 +113,22 @@ protected function getBatchSize(): int {
return $this->appConfig->getAppValueInt('indexing_batch_size', 100);
}

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

/**
* @param QueueFile[] $files
* @return void
* @throws \RuntimeException|\ErrorException
*/
protected function index(array $files): void {
$maxTime = $this->getMaxIndexingTime();
$startTime = time();
foreach ($files as $queueFile) {
if ($startTime + $maxTime < time()) {
break;
}
$file = current($this->rootFolder->getById($queueFile->getFileId()));
if (!$file instanceof File) {
continue;
Expand Down

0 comments on commit c996ecf

Please sign in to comment.