mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 09:42:09 -04:00
Merge pull request #60844 from nextcloud/fix/noid/files-join-ext-cache-select-fields
feat(file-search): add property to SearchQuery and check select fields to decide wheter to join extended cache
This commit is contained in:
commit
3592f83218
4 changed files with 34 additions and 6 deletions
|
|
@ -346,6 +346,15 @@ class FileSearchBackend implements ISearchBackend {
|
|||
}
|
||||
}, $query->orderBy);
|
||||
|
||||
$selectFields = [];
|
||||
foreach ($query->select as $searchProperty) {
|
||||
try {
|
||||
$selectFields[] = $this->mapPropertyNameToColumn($searchProperty);
|
||||
} catch (\InvalidArgumentException) {
|
||||
// property does not represent a column on DB
|
||||
}
|
||||
}
|
||||
|
||||
$limit = $query->limit;
|
||||
$maxResults = $limit->maxResults !== 0 ? (int)$limit->maxResults : 100;
|
||||
$offset = $limit->firstResult;
|
||||
|
|
@ -379,7 +388,8 @@ class FileSearchBackend implements ISearchBackend {
|
|||
$offset,
|
||||
$orders,
|
||||
$this->user,
|
||||
$limitHome
|
||||
$limitHome,
|
||||
$selectFields
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,13 +150,16 @@ class QuerySearchHelper {
|
|||
|
||||
$builder = $this->getQueryBuilder();
|
||||
|
||||
$requestedFields = $this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation());
|
||||
$requestedFields = array_merge(
|
||||
$this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation()),
|
||||
array_map(fn ($order) => $order->getField(), $searchQuery->getOrder()),
|
||||
$searchQuery->getSelectFields(),
|
||||
);
|
||||
|
||||
$orderFields = array_map(fn ($order) => $order->getField(), $searchQuery->getOrder());
|
||||
|
||||
$joinExtendedCache = in_array('creation_time', $requestedFields)
|
||||
$joinExtendedCache = in_array('metadata_etag', $requestedFields)
|
||||
|| in_array('creation_time', $requestedFields)
|
||||
|| in_array('upload_time', $requestedFields)
|
||||
|| in_array('last_activity', $orderFields);
|
||||
|| in_array('last_activity', $requestedFields);
|
||||
|
||||
$query = $builder->selectFileCache('file', $joinExtendedCache);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use OCP\IUser;
|
|||
class SearchQuery implements ISearchQuery {
|
||||
/**
|
||||
* @param ISearchOrder[] $order
|
||||
* @param list<string> $selectFields
|
||||
*/
|
||||
public function __construct(
|
||||
private ISearchOperator $searchOperation,
|
||||
|
|
@ -25,6 +26,7 @@ class SearchQuery implements ISearchQuery {
|
|||
private array $order,
|
||||
private ?IUser $user = null,
|
||||
private bool $limitToHome = false,
|
||||
private array $selectFields = [],
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -60,4 +62,9 @@ class SearchQuery implements ISearchQuery {
|
|||
public function limitToHome(): bool {
|
||||
return $this->limitToHome;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getSelectFields(): array {
|
||||
return $this->selectFields;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,4 +58,12 @@ interface ISearchQuery {
|
|||
* @since 18.0.0
|
||||
*/
|
||||
public function limitToHome(): bool;
|
||||
|
||||
/**
|
||||
* The fields to include in the search results
|
||||
*
|
||||
* @return list<string>
|
||||
* @since 35.0.0
|
||||
*/
|
||||
public function getSelectFields(): array;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue