Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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 <[email protected]>
  • Loading branch information
blizzz committed May 10, 2023
commit df662f50bdfadbb72e48202dd52c689f8c122b9c
1 change: 0 additions & 1 deletion lib/private/Files/Cache/CacheQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function selectTagUsage(): self {
$this->expr()->eq('systemtag.id', 'systemtagmap.systemtagid'),
$this->expr()->eq('systemtag.visibility', $this->createNamedParameter(true))
))
->where($this->expr()->like('systemtag.name', $this->createNamedParameter('_%')))
->groupBy('systemtag.name', 'systemtag.id', 'systemtag.visibility', 'systemtag.editable');

return $this;
Expand Down
2 changes: 0 additions & 2 deletions lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchQuery;
Expand Down Expand Up @@ -228,5 +227,4 @@ public function getCachesAndMountPointsForSearch(Root $root, string $path, bool

return [$caches, $mountByMountPoint];
}

}
12 changes: 8 additions & 4 deletions lib/private/SystemTag/SystemTagsInFilesDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

use OC\Files\Cache\QuerySearchHelper;
use OC\Files\Node\Root;
use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OCP\Files\Folder;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;

class SystemTagsInFilesDetector {
Expand All @@ -43,13 +45,15 @@ public function detectAssignedSystemTagsIn(
int $limit = 0,
int $offset = 0
): array {
$operator = new SearchComparison(ISearchComparison::COMPARE_LIKE, 'systemtag', '%');
// Currently query has to have exactly one search condition. If no media type is provided,
// we fall back to the presence of a system tag.
if (empty($filteredMediaType)) {
$query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'systemtag', '%'), $limit, $offset, []);
} else {
$query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $filteredMediaType . '/%'), $limit, $offset, []);
if ($filteredMediaType !== '') {
$mimeOperator = new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $filteredMediaType . '/%');
$operator = new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [$operator, $mimeOperator]);
}

$query = new SearchQuery($operator, $limit, $offset, []);
[$caches, ] = $this->searchHelper->getCachesAndMountPointsForSearch(
$this->getRootFolder($folder),
$folder->getPath(),
Expand Down