diff options
author | Robin Appelman <robin@icewind.nl> | 2021-11-16 18:15:59 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-12-02 17:35:02 +0100 |
commit | 38921ab498cb331e8bf516c2a587267266ff5a3f (patch) | |
tree | 8a06502aa4055b28ac0bd81a309b8209290a3eac /apps/files/lib | |
parent | f5fe887b4b8bfad2f781c9cd7df221e73758ded2 (diff) | |
download | nextcloud-server-38921ab498cb331e8bf516c2a587267266ff5a3f.tar.gz nextcloud-server-38921ab498cb331e8bf516c2a587267266ff5a3f.zip |
find users for background scan one by one
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files/lib')
-rw-r--r-- | apps/files/lib/BackgroundJob/ScanFiles.php | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/apps/files/lib/BackgroundJob/ScanFiles.php b/apps/files/lib/BackgroundJob/ScanFiles.php index f0c318882dd..37416aed521 100644 --- a/apps/files/lib/BackgroundJob/ScanFiles.php +++ b/apps/files/lib/BackgroundJob/ScanFiles.php @@ -21,6 +21,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ + namespace OCA\Files\BackgroundJob; use OC\Files\Utils\Scanner; @@ -40,8 +41,6 @@ use OCP\IUserManager; class ScanFiles extends \OC\BackgroundJob\TimedJob { /** @var IConfig */ private $config; - /** @var IUserManager */ - private $userManager; /** @var IEventDispatcher */ private $dispatcher; /** @var ILogger */ @@ -53,23 +52,20 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob { /** * @param IConfig $config - * @param IUserManager $userManager * @param IEventDispatcher $dispatcher * @param ILogger $logger * @param IDBConnection $connection */ public function __construct( - IConfig $config, - IUserManager $userManager, + IConfig $config, IEventDispatcher $dispatcher, - ILogger $logger, - IDBConnection $connection + ILogger $logger, + IDBConnection $connection ) { // Run once per 10 minutes $this->setInterval(60 * 10); $this->config = $config; - $this->userManager = $userManager; $this->dispatcher = $dispatcher; $this->logger = $logger; $this->connection = $connection; @@ -81,10 +77,10 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob { protected function runScanner(string $user) { try { $scanner = new Scanner( - $user, - null, - $this->dispatcher, - $this->logger + $user, + null, + $this->dispatcher, + $this->logger ); $scanner->backgroundScan(''); } catch (\Exception $e) { @@ -94,20 +90,20 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob { } /** - * Find all storages which have unindexed files and return a user for each + * Find a storage which have unindexed files and return a user with access to the storage * - * @return string[] + * @return string|false */ - private function getUsersToScan(): array { + private function getUserToScan() { $query = $this->connection->getQueryBuilder(); - $query->select($query->func()->max('user_id')) + $query->select('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))) - ->groupBy('storage_id') - ->setMaxResults(self::USERS_PER_SESSION); + ->andWhere($query->expr()->gt('parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT))) + ->setMaxResults(1); - return $query->execute()->fetchAll(\PDO::FETCH_COLUMN); + return $query->execute()->fetchOne(); } /** @@ -119,10 +115,12 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob { return; } - $users = $this->getUsersToScan(); - - foreach ($users as $user) { + $usersScanned = 0; + $user = $this->getUserToScan(); + while ($user && $usersScanned < self::USERS_PER_SESSION) { $this->runScanner($user); + $user = $this->getUserToScan(); + $usersScanned += 1; } } } |