summaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Node
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2021-05-05 19:36:41 +0200
committerRobin Appelman <robin@icewind.nl>2021-06-14 16:11:29 +0200
commit5d1d53c42e9a8342f9fd2da815e6653a64203c0c (patch)
treeab4821636cf77ef7d4cfa0cacaceff12d430692f /lib/private/Files/Node
parent9774fb1573d30e79eb57f8956f64b13b52b7dee9 (diff)
downloadnextcloud-server-5d1d53c42e9a8342f9fd2da815e6653a64203c0c.tar.gz
nextcloud-server-5d1d53c42e9a8342f9fd2da815e6653a64203c0c.zip
perform file search in a single query
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Files/Node')
-rw-r--r--lib/private/Files/Node/Folder.php71
1 files changed, 20 insertions, 51 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index 7198c576fd9..82515feba03 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -30,6 +30,10 @@
*/
namespace OC\Files\Node;
+use OC\DB\QueryBuilder\Literal;
+use OC\Files\Cache\QuerySearchHelper;
+use OC\Files\Search\SearchBinaryOperator;
+use OC\Files\Cache\Wrapper\CacheJail;
use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchOrder;
@@ -252,69 +256,34 @@ class Folder extends Node implements \OCP\Files\Folder {
$mount = $this->root->getMount($this->path);
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($this->path);
- $internalPath = rtrim($internalPath, '/');
- if ($internalPath !== '') {
- $internalPath = $internalPath . '/';
- }
-
- $subQueryLimit = $query->getLimit() > 0 ? $query->getLimit() + $query->getOffset() : 0;
- $rootQuery = new SearchQuery(
- new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
- new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $internalPath . '%'),
- $query->getSearchOperation(),
- ]),
- $subQueryLimit,
- 0,
- $query->getOrder(),
- $query->getUser()
- );
-
- $files = [];
- $cache = $storage->getCache('');
-
- $results = $cache->searchQuery($rootQuery);
- foreach ($results as $result) {
- $files[] = $this->cacheEntryToFileInfo($mount, '', $internalPath, $result);
- }
+ $caches = ['' => new CacheJail($storage->getCache(''), $internalPath)];
+ /** @var array{IMountPoint, string}[] $infoParams */
+ $infoParams = [
+ '' => [$mount, '']
+ ];
if (!$limitToHome) {
$mounts = $this->root->getMountsIn($this->path);
foreach ($mounts as $mount) {
- $subQuery = new SearchQuery(
- $query->getSearchOperation(),
- $subQueryLimit,
- 0,
- $query->getOrder(),
- $query->getUser()
- );
-
$storage = $mount->getStorage();
if ($storage) {
- $cache = $storage->getCache('');
-
$relativeMountPoint = ltrim(substr($mount->getMountPoint(), $rootLength), '/');
- $results = $cache->searchQuery($subQuery);
- foreach ($results as $result) {
- $files[] = $this->cacheEntryToFileInfo($mount, $relativeMountPoint, '', $result);
- }
+ $caches[$relativeMountPoint] = $storage->getCache('');
+ $infoParams[$relativeMountPoint] = [$mount, ''];
}
}
}
- $order = $query->getOrder();
- if ($order) {
- usort($files, function (FileInfo $a, FileInfo $b) use ($order) {
- foreach ($order as $orderField) {
- $cmp = $orderField->sortFileInfo($a, $b);
- if ($cmp !== 0) {
- return $cmp;
- }
- }
- return 0;
- });
- }
- $files = array_values(array_slice($files, $query->getOffset(), $query->getLimit() > 0 ? $query->getLimit() : null));
+ /** @var QuerySearchHelper $searchHelper */
+ $searchHelper = \OC::$server->get(QuerySearchHelper::class);
+ $resultsPerCache = $searchHelper->searchInCaches($query, $caches);
+ $files = array_merge(...array_map(function(array $results, $relativeMountPoint) use ($infoParams) {
+ $params = $infoParams[$relativeMountPoint];
+ return array_map(function(ICacheEntry $result) use ($relativeMountPoint, $params) {
+ return $this->cacheEntryToFileInfo($params[0], $relativeMountPoint, $params[1], $result);
+ }, $results);
+ }, array_values($resultsPerCache), array_keys($resultsPerCache)));
return array_map(function (FileInfo $file) {
return $this->createNode($file->getPath(), $file);