From 424db15deaef20856e29ba1c886f06864a393eea Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 10 Mar 2021 18:46:18 +0100 Subject: [PATCH 1/2] 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 --- apps/files/lib/Search/FilesSearchProvider.php | 5 +++-- lib/private/Search/Provider/File.php | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php index 9360011935..1c4bc75ade 100644 --- a/apps/files/lib/Search/FilesSearchProvider.php +++ b/apps/files/lib/Search/FilesSearchProvider.php @@ -103,7 +103,7 @@ class FilesSearchProvider implements IProvider { // 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 @@ -121,7 +121,8 @@ class FilesSearchProvider implements IProvider { $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() ); } diff --git a/lib/private/Search/Provider/File.php b/lib/private/Search/Provider/File.php index b4e35d374c..688b6ad1e9 100644 --- a/lib/private/Search/Provider/File.php +++ b/lib/private/Search/Provider/File.php @@ -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 From b62ee577d7032273540c5332d9aa151646ce241c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 11 Mar 2021 17:10:24 +0100 Subject: [PATCH 2/2] implement PagedProvider for file search Signed-off-by: Robin Appelman --- lib/private/Search/Provider/File.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/private/Search/Provider/File.php b/lib/private/Search/Provider/File.php index 688b6ad1e9..4125b1f7d7 100644 --- a/lib/private/Search/Provider/File.php +++ b/lib/private/Search/Provider/File.php @@ -30,12 +30,13 @@ namespace OC\Search\Provider; use OC\Files\Filesystem; +use OCP\Search\PagedProvider; /** * Provide search results from the 'files' app * @deprecated 20.0.0 */ -class File extends \OCP\Search\Provider { +class File extends PagedProvider { /** * Search for files and folders matching the given query @@ -88,4 +89,12 @@ class File extends \OCP\Search\Provider { // return return $results; } + + public function searchPaged($query, $page, $size) { + if ($size === 0) { + return $this->search($query); + } else { + return $this->search($query, $size, ($page - 1) * $size); + } + } }