Skip to content

Commit

Permalink
fix: CacheQueryBuilder API changed in 28
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Nov 19, 2023
1 parent a83f28f commit a00e42d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
16 changes: 8 additions & 8 deletions lib/Service/IgnoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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)))
Expand Down
28 changes: 12 additions & 16 deletions lib/Service/StorageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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,
) {
}

/**
Expand All @@ -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()
Expand Down Expand Up @@ -101,7 +97,7 @@ public function getMounts(): \Generator {
* @return \Generator<int,array{fileid:int, image:bool, video:bool, audio:bool},mixed,void>
*/
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)))
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions tests/stub.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a00e42d

Please sign in to comment.