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 <robin@icewind.nl>
This commit is contained in:
parent
a50f4a42bc
commit
57042ab107
|
@ -102,7 +102,7 @@ class FilesSearchProvider implements IProvider {
|
||||||
// Make sure we setup the users filesystem
|
// Make sure we setup the users filesystem
|
||||||
$this->rootFolder->getUserFolder($user->getUID());
|
$this->rootFolder->getUserFolder($user->getUID());
|
||||||
|
|
||||||
return SearchResult::complete(
|
return SearchResult::paginated(
|
||||||
$this->l10n->t('Files'),
|
$this->l10n->t('Files'),
|
||||||
array_map(function (FileResult $result) {
|
array_map(function (FileResult $result) {
|
||||||
// Generate thumbnail url
|
// Generate thumbnail url
|
||||||
|
@ -117,7 +117,8 @@ class FilesSearchProvider implements IProvider {
|
||||||
$this->urlGenerator->getAbsoluteURL($result->link),
|
$this->urlGenerator->getAbsoluteURL($result->link),
|
||||||
$result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type)
|
$result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type)
|
||||||
);
|
);
|
||||||
}, $this->fileSearch->search($query->getTerm()))
|
}, $this->fileSearch->search($query->getTerm(), $query->getLimit(), (int)$query->getCursor())),
|
||||||
|
$query->getCursor() + $query->getLimit()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,23 @@ class File extends \OCP\Search\Provider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for files and folders matching the given query
|
* Search for files and folders matching the given query
|
||||||
|
*
|
||||||
* @param string $query
|
* @param string $query
|
||||||
|
* @param int|null $limit
|
||||||
|
* @param int|null $offset
|
||||||
* @return \OCP\Search\Result[]
|
* @return \OCP\Search\Result[]
|
||||||
* @deprecated 20.0.0
|
* @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);
|
$files = Filesystem::search($query);
|
||||||
$results = [];
|
$results = [];
|
||||||
|
if ($limit !== null) {
|
||||||
|
$files = array_slice($files, $offset, $offset + $limit);
|
||||||
|
}
|
||||||
// edit results
|
// edit results
|
||||||
foreach ($files as $fileData) {
|
foreach ($files as $fileData) {
|
||||||
// skip versions
|
// skip versions
|
||||||
|
|
Loading…
Reference in New Issue