Skip to content

Commit df77c7d

Browse files
icewind1991PVince81
authored andcommitted
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>
1 parent 0e30c82 commit df77c7d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/private/Search/Provider/File.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,31 @@
2929
namespace OC\Search\Provider;
3030

3131
use OC\Files\Filesystem;
32+
use OCP\Search\PagedProvider;
3233

3334
/**
3435
* Provide search results from the 'files' app
3536
*/
36-
class File extends \OCP\Search\Provider {
37+
class File extends PagedProvider {
3738

3839
/**
3940
* Search for files and folders matching the given query
41+
*
4042
* @param string $query
41-
* @return \OCP\Search\Result
43+
* @param int|null $limit
44+
* @param int|null $offset
45+
* @return \OCP\Search\Result[]
4246
*/
43-
public function search($query) {
47+
public function search($query, int $limit = null, int $offset = null) {
48+
if ($offset === null) {
49+
$offset = 0;
50+
}
51+
\OC_Util::setupFS();
4452
$files = Filesystem::search($query);
4553
$results = [];
54+
if ($limit !== null) {
55+
$files = array_slice($files, $offset, $offset + $limit);
56+
}
4657
// edit results
4758
foreach ($files as $fileData) {
4859
// skip versions
@@ -75,4 +86,12 @@ public function search($query) {
7586
// return
7687
return $results;
7788
}
89+
90+
public function searchPaged($query, $page, $size) {
91+
if ($size === 0) {
92+
return $this->search($query);
93+
} else {
94+
return $this->search($query, $size, ($page - 1) * $size);
95+
}
96+
}
7897
}

0 commit comments

Comments
 (0)