Skip to content

Commit

Permalink
fix: ignore files in appdata when counting unscanned files
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed Nov 13, 2024
1 parent 2fc7fde commit 2c5347a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/BackgroundJob/BackgroundScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IConfig;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;

Expand All @@ -35,6 +36,7 @@ class BackgroundScanner extends TimedJob {
protected ItemFactory $itemFactory;
private IUserMountCache $userMountCache;
private IEventDispatcher $eventDispatcher;
private IConfig $config;
private bool $isCLI;

public function __construct(
Expand All @@ -48,6 +50,7 @@ public function __construct(
ItemFactory $itemFactory,
IUserMountCache $userMountCache,
IEventDispatcher $eventDispatcher,
IConfig $config,
bool $isCLI
) {
parent::__construct($timeFactory);
Expand All @@ -60,6 +63,7 @@ public function __construct(
$this->itemFactory = $itemFactory;
$this->userMountCache = $userMountCache;
$this->eventDispatcher = $eventDispatcher;
$this->config = $config;
$this->isCLI = $isCLI;

// Run once per 15 minutes
Expand Down Expand Up @@ -202,6 +206,7 @@ protected function getSizeLimitExpression(IQueryBuilder $qb) {
*/
public function getUnscannedFiles() {
$dirMimeTypeId = $this->mimeTypeLoader->getId(FileInfo::MIMETYPE_FOLDER);
$instanceId = $this->config->getSystemValue('instanceid', '');

$query = $this->db->getQueryBuilder();
$query->select('fc.fileid')
Expand All @@ -214,6 +219,7 @@ public function getUnscannedFiles() {
$query->expr()->like('path', $query->createNamedParameter('files/%')),
$query->expr()->notLike('s.id', $query->createNamedParameter('home::%'))
))
->andWhere($query->expr()->notLike('fc.path', $query->createNamedParameter("appdata_$instanceId/%")))
->andWhere($this->getSizeLimitExpression($query))
->setMaxResults($this->getBatchSize() * 10);

Expand Down
2 changes: 2 additions & 0 deletions tests/BackgroundScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCP\Files\Folder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;
use Test\Traits\MountProviderTrait;
Expand Down Expand Up @@ -104,6 +105,7 @@ private function getBackgroundScanner(): BackgroundScanner {
\OC::$server->get(ItemFactory::class),
\OC::$server->get(IUserMountCache::class),
\OC::$server->get(IEventDispatcher::class),
\OC::$server->get(IConfig::class),
false
);
}
Expand Down

0 comments on commit 2c5347a

Please sign in to comment.