Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Loop for the recent search
Else it might happen that less entries than requested are returned

Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Feb 13, 2019
commit cb67c6aa003c41339bf68683bd1cd2855baed44d
29 changes: 26 additions & 3 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,30 @@ public function getRecent($limit, $offset = 0) {
$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.*')
Expand All @@ -392,9 +414,10 @@ public function getRecent($limit, $offset = 0) {
->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'];
Expand Down