mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 18:50:47 -04:00
feat(file-search): add property to SearchQuery and check select fields to decide wheter to join extended cache
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
This commit is contained in:
parent
5923f90c12
commit
01ae42f615
4 changed files with 37 additions and 6 deletions
|
|
@ -342,6 +342,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;
|
||||
|
|
@ -375,7 +384,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);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ class SearchQuery implements ISearchQuery {
|
|||
/** @var ?IUser */
|
||||
private $user;
|
||||
private $limitToHome;
|
||||
/** @var array */
|
||||
private $selectFields;
|
||||
|
||||
/**
|
||||
* SearchQuery constructor.
|
||||
|
|
@ -33,6 +35,7 @@ class SearchQuery implements ISearchQuery {
|
|||
* @param array $order
|
||||
* @param ?IUser $user
|
||||
* @param bool $limitToHome
|
||||
* @param list<string> $selectFields
|
||||
*/
|
||||
public function __construct(
|
||||
ISearchOperator $searchOperation,
|
||||
|
|
@ -41,6 +44,7 @@ class SearchQuery implements ISearchQuery {
|
|||
array $order,
|
||||
?IUser $user = null,
|
||||
bool $limitToHome = false,
|
||||
array $selectFields = [],
|
||||
) {
|
||||
$this->searchOperation = $searchOperation;
|
||||
$this->limit = $limit;
|
||||
|
|
@ -48,6 +52,7 @@ class SearchQuery implements ISearchQuery {
|
|||
$this->order = $order;
|
||||
$this->user = $user;
|
||||
$this->limitToHome = $limitToHome;
|
||||
$this->selectFields = $selectFields;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -88,4 +93,9 @@ class SearchQuery implements ISearchQuery {
|
|||
public function limitToHome(): bool {
|
||||
return $this->limitToHome;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getSelectFields(): array {
|
||||
return $this->selectFields;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,4 +57,12 @@ interface ISearchQuery {
|
|||
* @since 18.0.0
|
||||
*/
|
||||
public function limitToHome(): bool;
|
||||
|
||||
/**
|
||||
* The fields to include in the search results
|
||||
*
|
||||
* @return list<string>
|
||||
* @since 32.0.12
|
||||
*/
|
||||
public function getSelectFields(): array;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue