Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis <6653109+artonge@users.noreply.github.com>2021-12-08 19:57:46 +0300
committerGitHub <noreply@github.com>2021-12-08 19:57:46 +0300
commit010be3d7753b177330a692c21908d52e5452c59f (patch)
tree0ec6a67b63b47800c3a0a8d00849e20cd18dd9af /apps/files
parentbb44a150a23ffa3619b07a20321b007725f98f78 (diff)
parentdce2198f897df706df38ce8c40202b2b63110703 (diff)
Merge pull request #30057 from nextcloud/backport/29735/stable22
[stable22] find users for background scan one by one
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/lib/BackgroundJob/ScanFiles.php43
-rw-r--r--apps/files/tests/BackgroundJob/ScanFilesTest.php3
2 files changed, 23 insertions, 23 deletions
diff --git a/apps/files/lib/BackgroundJob/ScanFiles.php b/apps/files/lib/BackgroundJob/ScanFiles.php
index f0c318882dd..84846b9b55d 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;
@@ -29,7 +30,6 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\ILogger;
-use OCP\IUserManager;
/**
* Class ScanFiles is a background job used to run the file scanner over the user
@@ -40,8 +40,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,14 +51,12 @@ 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,
IEventDispatcher $dispatcher,
ILogger $logger,
IDBConnection $connection
@@ -69,7 +65,6 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob {
$this->setInterval(60 * 10);
$this->config = $config;
- $this->userManager = $userManager;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
$this->connection = $connection;
@@ -81,10 +76,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 +89,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 +114,18 @@ class ScanFiles extends \OC\BackgroundJob\TimedJob {
return;
}
- $users = $this->getUsersToScan();
-
- foreach ($users as $user) {
+ $usersScanned = 0;
+ $lastUser = '';
+ $user = $this->getUserToScan();
+ while ($user && $usersScanned < self::USERS_PER_SESSION && $lastUser !== $user) {
$this->runScanner($user);
+ $lastUser = $user;
+ $user = $this->getUserToScan();
+ $usersScanned += 1;
+ }
+
+ if ($lastUser === $user) {
+ $this->logger->warning("User $user still has unscanned files after running background scan, background scan might be stopped prematurely");
}
}
}
diff --git a/apps/files/tests/BackgroundJob/ScanFilesTest.php b/apps/files/tests/BackgroundJob/ScanFilesTest.php
index f1fb505fe53..04eeff4a30b 100644
--- a/apps/files/tests/BackgroundJob/ScanFilesTest.php
+++ b/apps/files/tests/BackgroundJob/ScanFilesTest.php
@@ -30,7 +30,6 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser;
-use OCP\IUserManager;
use Test\TestCase;
use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait;
@@ -54,7 +53,6 @@ class ScanFilesTest extends TestCase {
parent::setUp();
$config = $this->createMock(IConfig::class);
- $userManager = $this->createMock(IUserManager::class);
$dispatcher = $this->createMock(IEventDispatcher::class);
$logger = $this->createMock(ILogger::class);
$connection = \OC::$server->getDatabaseConnection();
@@ -63,7 +61,6 @@ class ScanFilesTest extends TestCase {
$this->scanFiles = $this->getMockBuilder('\OCA\Files\BackgroundJob\ScanFiles')
->setConstructorArgs([
$config,
- $userManager,
$dispatcher,
$logger,
$connection,