diff --git a/lib/Service/IgnoreService.php b/lib/Service/IgnoreService.php index b9a63c19..e2a1facd 100644 --- a/lib/Service/IgnoreService.php +++ b/lib/Service/IgnoreService.php @@ -9,22 +9,22 @@ use OC\Files\Cache\CacheQueryBuilder; use OC\SystemConfig; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\FilesMetadata\IFilesMetadataManager; use OCP\ICache; use OCP\ICacheFactory; use OCP\IDBConnection; use Psr\Log\LoggerInterface; class IgnoreService { - private IDBConnection $db; - private SystemConfig $systemConfig; - private LoggerInterface $logger; private array $inMemoryCache = []; private ICache $localCache; - public function __construct(IDBConnection $db, SystemConfig $systemConfig, LoggerInterface $logger, ICacheFactory $cacheFactory) { - $this->db = $db; - $this->systemConfig = $systemConfig; - $this->logger = $logger; + public function __construct( + private IDBConnection $db, + private SystemConfig $systemConfig, + private LoggerInterface $logger, + ICacheFactory $cacheFactory, + private IFilesMetadataManager $metadataManager) { $this->localCache = $cacheFactory->createLocal('recognize-ignored-directories'); } @@ -45,7 +45,7 @@ public function getIgnoredDirectories(int $storageId, array $ignoreMarkers): arr return $directories; } - $qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger); + $qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger, $this->metadataManager); $result = $qb->selectFileCache() ->andWhere($qb->expr()->in('name', $qb->createNamedParameter($ignoreMarkers, IQueryBuilder::PARAM_STR_ARRAY))) ->andWhere($qb->expr()->eq('storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) diff --git a/lib/Service/StorageService.php b/lib/Service/StorageService.php index 2f937358..ed670751 100644 --- a/lib/Service/StorageService.php +++ b/lib/Service/StorageService.php @@ -17,8 +17,8 @@ use OCP\DB\Exception; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\IMimeTypeLoader; +use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IDBConnection; -use Psr\Log\LoggerInterface; class StorageService { public const ALLOWED_MOUNT_TYPES = [ @@ -33,18 +33,14 @@ class StorageService { 'OC\Files\Mount\ObjectHomeMountProvider', ]; - private IDBConnection $db; - private LoggerInterface $logger; - private SystemConfig $systemConfig; - private IgnoreService $ignoreService; - private IMimeTypeLoader $mimeTypes; - - public function __construct(IDBConnection $db, Logger $logger, SystemConfig $systemConfig, IgnoreService $ignoreService, IMimeTypeLoader $mimeTypes) { - $this->db = $db; - $this->logger = $logger; - $this->systemConfig = $systemConfig; - $this->ignoreService = $ignoreService; - $this->mimeTypes = $mimeTypes; + public function __construct( + private IDBConnection $db, + private Logger $logger, + private SystemConfig $systemConfig, + private IgnoreService $ignoreService, + private IMimeTypeLoader $mimeTypes, + private IFilesMetadataManager $metadataManager, + ) { } /** @@ -68,7 +64,7 @@ public function getMounts(): \Generator { $overrideRoot = $rootId; if (in_array($row['mount_provider_class'], self::HOME_MOUNT_TYPES)) { // Only crawl files, not cache or trashbin - $qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger); + $qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger, $this->metadataManager); try { /** @var array|false $root */ $root = $qb->selectFileCache() @@ -101,7 +97,7 @@ public function getMounts(): \Generator { * @return \Generator */ public function getFilesInMount(int $storageId, int $rootId, array $models, int $lastFileId = 0, int $maxResults = 100) : \Generator { - $qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger); + $qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger, $this->metadataManager); try { $result = $qb->selectFileCache() ->andWhere($qb->expr()->eq('filecache.fileid', $qb->createNamedParameter($rootId, IQueryBuilder::PARAM_INT))) @@ -133,7 +129,7 @@ public function getFilesInMount(int $storageId, int $rootId, array $models, int $videoTypes = array_map(fn ($mimeType) => $this->mimeTypes->getId($mimeType), Constants::VIDEO_FORMATS); $audioTypes = array_map(fn ($mimeType) => $this->mimeTypes->getId($mimeType), Constants::AUDIO_FORMATS); - $qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger); + $qb = new CacheQueryBuilder($this->db, $this->systemConfig, $this->logger, $this->metadataManager); $ignoreFileidsExpr = []; if (count(array_intersect([ClusteringFaceClassifier::MODEL_NAME, ImagenetClassifier::MODEL_NAME, LandmarksClassifier::MODEL_NAME], $models)) > 0) { $expr = array_map(fn (string $path): string => $qb->expr()->notLike('path', $qb->createNamedParameter($path ? $path . '/%' : '%')), $ignorePathsImage); diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 25f781f9..9fde8ef5 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -22,8 +22,13 @@ namespace OC { namespace OC\Files\Cache { - class CacheQueryBuilder extends \OCP\DB\QueryBuilder\IQueryBuilder { - public function __construct(\OCP\IDBCOnnection $db, \OC\SystemConfig $config, \Psr\Log\LoggerInterface $logger); + + use OCP\FilesMetadata\IFilesMetadataManager; + use OCP\IDBConnection; + use Psr\Log\LoggerInterface; + + class CacheQueryBuilder extends \OCP\DB\QueryBuilder\IQueryBuilder { + public function __construct(\OCP\IDBCOnnection $db, \OC\SystemConfig $config, \Psr\Log\LoggerInterface $logger, \OCP\FilesMetadata\IFilesMetadataManager $filesMetadataManager); public function selectFileCache(string $alias = null, bool $joinExtendedCache = true):CacheQueryBuilder; public function whereStorageId(int $storageId):CacheQueryBuilder; public function whereFileId(int $fileId):CacheQueryBuilder;