Skip to content

Commit 12fdc19

Browse files
committed
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]>
1 parent 62929cc commit 12fdc19

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

apps/files/lib/Search/FilesSearchProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
103103
// Make sure we setup the users filesystem
104104
$this->rootFolder->getUserFolder($user->getUID());
105105

106-
return SearchResult::complete(
106+
return SearchResult::paginated(
107107
$this->l10n->t('Files'),
108108
array_map(function (FileResult $result) {
109109
// Generate thumbnail url
@@ -121,7 +121,8 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
121121
$searchResultEntry->addAttribute('fileId', (string)$result->id);
122122
$searchResultEntry->addAttribute('path', $result->path);
123123
return $searchResultEntry;
124-
}, $this->fileSearch->search($query->getTerm()))
124+
}, $this->fileSearch->search($query->getTerm(), $query->getLimit(), (int)$query->getCursor())),
125+
$query->getCursor() + $query->getLimit()
125126
);
126127
}
127128

lib/private/Search/Provider/File.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,23 @@ class File extends \OCP\Search\Provider {
3939

4040
/**
4141
* Search for files and folders matching the given query
42+
*
4243
* @param string $query
44+
* @param int|null $limit
45+
* @param int|null $offset
4346
* @return \OCP\Search\Result[]
4447
* @deprecated 20.0.0
4548
*/
46-
public function search($query) {
49+
public function search($query, int $limit = null, int $offset = null) {
50+
if ($offset === null) {
51+
$offset = 0;
52+
}
4753
\OC_Util::setupFS();
4854
$files = Filesystem::search($query);
4955
$results = [];
56+
if ($limit !== null) {
57+
$files = array_slice($files, $offset, $offset + $limit);
58+
}
5059
// edit results
5160
foreach ($files as $fileData) {
5261
// skip versions

0 commit comments

Comments
 (0)