Skip to content

Commit 298af3c

Browse files
committed
refactor: remove where specification from SELECT getter
- search constraints are now fully in control of SystemTagsInFilesDetector::detectAssignedSystemTagsIn(), avoids duplication of a WHERE statement Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent f2b5a07 commit 298af3c

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lib/private/Files/Cache/CacheQueryBuilder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public function selectTagUsage(): self {
5555
$this->expr()->eq('systemtag.id', 'systemtagmap.systemtagid'),
5656
$this->expr()->eq('systemtag.visibility', $this->createNamedParameter(true))
5757
))
58-
->where($this->expr()->like('systemtag.name', $this->createNamedParameter('_%')))
5958
->groupBy('systemtag.name', 'systemtag.id', 'systemtag.visibility', 'systemtag.editable');
6059

6160
return $this;

lib/private/Files/Cache/QuerySearchHelper.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use OCP\Files\Cache\ICacheEntry;
3636
use OCP\Files\Folder;
3737
use OCP\Files\IMimeTypeLoader;
38-
use OCP\Files\IRootFolder;
3938
use OCP\Files\Mount\IMountPoint;
4039
use OCP\Files\Search\ISearchBinaryOperator;
4140
use OCP\Files\Search\ISearchQuery;
@@ -228,5 +227,4 @@ public function getCachesAndMountPointsForSearch(Root $root, string $path, bool
228227

229228
return [$caches, $mountByMountPoint];
230229
}
231-
232230
}

lib/private/SystemTag/SystemTagsInFilesDetector.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828

2929
use OC\Files\Cache\QuerySearchHelper;
3030
use OC\Files\Node\Root;
31+
use OC\Files\Search\SearchBinaryOperator;
3132
use OC\Files\Search\SearchComparison;
3233
use OC\Files\Search\SearchQuery;
3334
use OCP\Files\Folder;
35+
use OCP\Files\Search\ISearchBinaryOperator;
3436
use OCP\Files\Search\ISearchComparison;
3537

3638
class SystemTagsInFilesDetector {
@@ -43,13 +45,15 @@ public function detectAssignedSystemTagsIn(
4345
int $limit = 0,
4446
int $offset = 0
4547
): array {
48+
$operator = new SearchComparison(ISearchComparison::COMPARE_LIKE, 'systemtag', '%');
4649
// Currently query has to have exactly one search condition. If no media type is provided,
4750
// we fall back to the presence of a system tag.
48-
if (empty($filteredMediaType)) {
49-
$query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'systemtag', '%'), $limit, $offset, []);
50-
} else {
51-
$query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $filteredMediaType . '/%'), $limit, $offset, []);
51+
if ($filteredMediaType !== '') {
52+
$mimeOperator = new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $filteredMediaType . '/%');
53+
$operator = new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [$operator, $mimeOperator]);
5254
}
55+
56+
$query = new SearchQuery($operator, $limit, $offset, []);
5357
[$caches, ] = $this->searchHelper->getCachesAndMountPointsForSearch(
5458
$this->getRootFolder($folder),
5559
$folder->getPath(),

0 commit comments

Comments
 (0)