diff options
author | Robin Appelman <robin@icewind.nl> | 2021-05-05 19:36:41 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-06-14 16:11:29 +0200 |
commit | 5d1d53c42e9a8342f9fd2da815e6653a64203c0c (patch) | |
tree | ab4821636cf77ef7d4cfa0cacaceff12d430692f /lib/private/Files/Cache/QuerySearchHelper.php | |
parent | 9774fb1573d30e79eb57f8956f64b13b52b7dee9 (diff) | |
download | nextcloud-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/Cache/QuerySearchHelper.php')
-rw-r--r-- | lib/private/Files/Cache/QuerySearchHelper.php | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 6bf3835df6c..64a888f492c 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -29,6 +29,7 @@ use OC\Files\Search\SearchBinaryOperator; use OC\SystemConfig; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Cache\ICache; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\IMimeTypeLoader; use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchComparison; @@ -254,9 +255,10 @@ class QuerySearchHelper { } /** + * @template T of array-key * @param ISearchQuery $searchQuery - * @param ICache[] $caches - * @return CacheEntry[] + * @param array<T, ICache> $caches + * @return array<T, ICacheEntry[]> */ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array { // search in multiple caches at once by creating one query in the following format @@ -297,9 +299,9 @@ class QuerySearchHelper { $query->andWhere($searchExpr); } - $storageFilters = array_map(function (ICache $cache) { + $storageFilters = array_values(array_map(function (ICache $cache) { return $cache->getQueryFilterForStorage(); - }, $caches); + }, $caches)); $query->andWhere($this->searchOperatorToDBExpr($builder, new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, $storageFilters))); if ($searchQuery->limitToHome() && ($this instanceof HomeCache)) { @@ -325,12 +327,12 @@ class QuerySearchHelper { $result->closeCursor(); // loop trough all caches for each result to see if the result matches that storage - $results = []; + $results = array_fill_keys(array_keys($caches), []); foreach ($rawEntries as $rawEntry) { - foreach ($caches as $cache) { + foreach ($caches as $cacheKey => $cache) { $entry = $cache->getCacheEntryFromSearchResult($rawEntry); if ($entry) { - $results[] = $entry; + $results[$cacheKey][] = $entry; } } } |