diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-02-13 21:22:16 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-02-13 21:22:16 +0100 |
commit | cb67c6aa003c41339bf68683bd1cd2855baed44d (patch) | |
tree | a1e2be2778718f9fd63b147571263bb119426685 /lib | |
parent | 4c7424d38b42ef2e1359095fcf620b2ef5cc3b77 (diff) | |
download | nextcloud-server-cb67c6aa003c41339bf68683bd1cd2855baed44d.tar.gz nextcloud-server-cb67c6aa003c41339bf68683bd1cd2855baed44d.zip |
Loop for the recent search
Else it might happen that less entries than requested are returned
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Node/Folder.php | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index 855515ad260..9051862eadd 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -377,8 +377,30 @@ class Folder extends Node implements \OCP\Files\Folder { $mountMap = array_combine($storageIds, $mounts); $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); - //todo look into options of filtering path based on storage id (only search in files/ for home storage, filter by share root for shared, etc) + // Search in batches of 500 entries + $searchLimit = 500; + $results = []; + do { + $searchResult = $this->recentSearch($searchLimit, $offset, $storageIds, $folderMimetype); + + // Exit condition if there are no more results + if (count($searchResult) === 0) { + break; + } + + $parseResult = $this->recentParse($searchResult, $mountMap, $mimetypeLoader); + + foreach ($parseResult as $result) { + $results[] = $result; + } + + $offset += $searchLimit; + } while (count($results) < $limit); + return array_slice($results, 0, $limit); + } + + private function recentSearch($limit, $offset, $storageIds, $folderMimetype) { $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); $query = $builder ->select('f.*') @@ -392,9 +414,10 @@ class Folder extends Node implements \OCP\Files\Folder { ->orderBy('f.mtime', 'DESC') ->setMaxResults($limit) ->setFirstResult($offset); + return $query->execute()->fetchAll(); + } - $result = $query->execute()->fetchAll(); - + private function recentParse($result, $mountMap, $mimetypeLoader) { $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { $mount = $mountMap[$entry['storage']]; $entry['internalPath'] = $entry['path']; |