summaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-10-05 15:42:59 +0200
committerRobin Appelman <robin@icewind.nl>2021-10-12 15:55:57 +0200
commit916a838873dc9c2b0adb53ecbad4b1170fd9bdd2 (patch)
treed69f3472d2cbac25e27bb56fb86eb0ef7519970f /lib/private/Files
parent6039a43d138b6505a2bde71d96a22bf542974c8b (diff)
downloadnextcloud-server-916a838873dc9c2b0adb53ecbad4b1170fd9bdd2.tar.gz
nextcloud-server-916a838873dc9c2b0adb53ecbad4b1170fd9bdd2.zip
[21] generate a better optimized query for path prefix search filters
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files')
-rw-r--r--lib/private/Files/Cache/Cache.php10
-rw-r--r--lib/private/Files/Cache/Wrapper/CacheJail.php40
2 files changed, 24 insertions, 26 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php
index b851076e2c1..ae707fb5b54 100644
--- a/lib/private/Files/Cache/Cache.php
+++ b/lib/private/Files/Cache/Cache.php
@@ -800,7 +800,7 @@ class Cache implements ICache {
* @param IResult $result
* @return CacheEntry[]
*/
- private function searchResultToCacheEntries(IResult $result): array {
+ protected function searchResultToCacheEntries(IResult $result): array {
$files = $result->fetchAll();
return array_map(function (array $data) {
@@ -837,7 +837,7 @@ class Cache implements ICache {
}, $files);
}
- public function searchQuery(ISearchQuery $searchQuery) {
+ protected function buildSearchQuery(ISearchQuery $searchQuery): IQueryBuilder {
$builder = $this->getQueryBuilder();
$query = $builder->selectFileCache('file');
@@ -877,6 +877,12 @@ class Cache implements ICache {
$query->setFirstResult($searchQuery->getOffset());
}
+ return $query;
+ }
+
+ public function searchQuery(ISearchQuery $searchQuery) {
+ $query = $this->buildSearchQuery($searchQuery);
+
$result = $query->execute();
$cacheEntries = $this->searchResultToCacheEntries($result);
$result->closeCursor();
diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php
index 8c6a1d21e76..5c4a75bfefc 100644
--- a/lib/private/Files/Cache/Wrapper/CacheJail.php
+++ b/lib/private/Files/Cache/Wrapper/CacheJail.php
@@ -29,13 +29,10 @@
namespace OC\Files\Cache\Wrapper;
use OC\Files\Cache\Cache;
-use OC\Files\Search\SearchBinaryOperator;
-use OC\Files\Search\SearchComparison;
+use OC\Files\Cache\QuerySearchHelper;
use OC\Files\Search\SearchQuery;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Cache\ICacheEntry;
-use OCP\Files\Search\ISearchBinaryOperator;
-use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchQuery;
/**
@@ -63,6 +60,7 @@ class CacheJail extends CacheWrapper {
} else {
$this->unjailedRoot = $root;
}
+ $this->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader);
}
protected function getRoot() {
@@ -260,7 +258,7 @@ class CacheJail extends CacheWrapper {
->whereStorageId()
->andWhere($query->expr()->orX(
$query->expr()->like('path', $query->createNamedParameter($this->getGetUnjailedRoot() . '/%')),
- $query->expr()->eq('path_hash', $query->createNamedParameter(md5($this->getGetUnjailedRoot()))),
+ $query->expr()->eq('path', $query->createNamedParameter($this->getGetUnjailedRoot())),
))
->andWhere($query->expr()->iLike('name', $query->createNamedParameter($pattern)));
@@ -292,7 +290,7 @@ class CacheJail extends CacheWrapper {
->whereStorageId()
->andWhere($query->expr()->orX(
$query->expr()->like('path', $query->createNamedParameter($this->getGetUnjailedRoot() . '/%')),
- $query->expr()->eq('path_hash', $query->createNamedParameter(md5($this->getGetUnjailedRoot()))),
+ $query->expr()->eq('path', $query->createNamedParameter($this->getGetUnjailedRoot())),
));
if (strpos($mimetype, '/')) {
@@ -311,27 +309,21 @@ class CacheJail extends CacheWrapper {
return $this->formatSearchResults($results);
}
- public function searchQuery(ISearchQuery $query) {
+ public function searchQuery(ISearchQuery $searchQuery) {
if ($this->getGetUnjailedRoot() === '' || $this->getGetUnjailedRoot() === '/') {
- return parent::searchQuery($query);
+ return parent::searchQuery($searchQuery);
}
- $prefixFilter = new SearchComparison(
- ISearchComparison::COMPARE_LIKE,
- 'path',
- $this->getGetUnjailedRoot() . '/%'
- );
- $rootFilter = new SearchComparison(
- ISearchComparison::COMPARE_EQUAL,
- 'path',
- $this->getGetUnjailedRoot()
- );
- $operation = new SearchBinaryOperator(
- ISearchBinaryOperator::OPERATOR_AND,
- [new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, [$prefixFilter, $rootFilter]) , $query->getSearchOperation()]
- );
- $simpleQuery = new SearchQuery($operation, $query->getLimit(), $query->getOffset(), $query->getOrder(), $query->getUser());
- $results = $this->getCache()->searchQuery($simpleQuery);
+ $query = $this->buildSearchQuery($searchQuery);
+
+ $query->andWhere($query->expr()->orX(
+ $query->expr()->like('path', $query->createNamedParameter($this->getGetUnjailedRoot() . '/%')),
+ $query->expr()->eq('path', $query->createNamedParameter($this->getGetUnjailedRoot())),
+ ));
+
+ $result = $query->execute();
+ $results = $this->searchResultToCacheEntries($result);
+ $result->closeCursor();
return $this->formatSearchResults($results);
}