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
0e30c82f30
commit
df77c7d37c
|
@ -29,20 +29,31 @@
|
|||
namespace OC\Search\Provider;
|
||||
|
||||
use OC\Files\Filesystem;
|
||||
use OCP\Search\PagedProvider;
|
||||
|
||||
/**
|
||||
* Provide search results from the 'files' app
|
||||
*/
|
||||
class File extends \OCP\Search\Provider {
|
||||
class File extends PagedProvider {
|
||||
|
||||
/**
|
||||
* Search for files and folders matching the given query
|
||||
*
|
||||
* @param string $query
|
||||
* @return \OCP\Search\Result
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
* @return \OCP\Search\Result[]
|
||||
*/
|
||||
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
|
||||
|
@ -75,4 +86,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue