Skip to content

Commit

Permalink
fix: make background scan job compatible with sharding
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jul 25, 2024
1 parent 2bd9f28 commit c0059ff
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions apps/files/lib/BackgroundJob/ScanFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class ScanFiles extends TimedJob {
public const USERS_PER_SESSION = 500;

public function __construct(
IConfig $config,
IConfig $config,
IEventDispatcher $dispatcher,
LoggerInterface $logger,
IDBConnection $connection,
ITimeFactory $time
LoggerInterface $logger,
IDBConnection $connection,
ITimeFactory $time
) {
parent::__construct($time);
// Run once per 10 minutes
Expand Down Expand Up @@ -71,14 +71,16 @@ protected function runScanner(string $user): void {
*/
private function getUserToScan() {
$query = $this->connection->getQueryBuilder();
$query->select('user_id')
$query->select('m.user_id')
->from('filecache', 'f')
->innerJoin('f', 'mounts', 'm', $query->expr()->eq('storage_id', 'storage'))
->where($query->expr()->lt('size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->gt('parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->setMaxResults(1);
->innerJoin('f', 'mounts', 'm', $query->expr()->eq('m.storage_id', 'f.storage'))
->where($query->expr()->lt('f.size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->gt('f.parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->setMaxResults(1)
->runAcrossAllShards();

return $query->executeQuery()->fetchOne();
$res = $query->executeQuery()->fetch();
return $res ? $res['user_id'] : false;
}

/**
Expand Down

0 comments on commit c0059ff

Please sign in to comment.