Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
limit constructing of result objects in file search
even thought we currently have no proper way of limiting the search itself, we can at least limit the construction of the result objects.

this saves about 40% of the time spend in the search request in my local testing

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 authored and backportbot[bot] committed Mar 12, 2021
commit b6af62fd247567dc59c7671b50829392ba2f294b
5 changes: 3 additions & 2 deletions apps/files/lib/Search/FilesSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
// Make sure we setup the users filesystem
$this->rootFolder->getUserFolder($user->getUID());

return SearchResult::complete(
return SearchResult::paginated(
$this->l10n->t('Files'),
array_map(function (FileResult $result) {
// Generate thumbnail url
Expand All @@ -121,7 +121,8 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$searchResultEntry->addAttribute('fileId', (string)$result->id);
$searchResultEntry->addAttribute('path', $result->path);
return $searchResultEntry;
}, $this->fileSearch->search($query->getTerm()))
}, $this->fileSearch->search($query->getTerm(), $query->getLimit(), (int)$query->getCursor())),
$query->getCursor() + $query->getLimit()
);
}

Expand Down
11 changes: 10 additions & 1 deletion lib/private/Search/Provider/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ class File extends \OCP\Search\Provider {

/**
* Search for files and folders matching the given query
*
* @param string $query
* @param int|null $limit
* @param int|null $offset
* @return \OCP\Search\Result[]
* @deprecated 20.0.0
*/
public function search($query) {
public function search($query, int $limit = null, int $offset = null) {
if ($offset === null) {
$offset = 0;
}
\OC_Util::setupFS();
$files = Filesystem::search($query);
$results = [];
if ($limit !== null) {
$files = array_slice($files, $offset, $offset + $limit);
}
// edit results
foreach ($files as $fileData) {
// skip versions
Expand Down