diff options
author | Robin Appelman <robin@icewind.nl> | 2021-03-19 13:35:37 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2021-03-19 13:35:37 +0100 |
commit | de713967c0f109b674a96fddbb591a85b3e246bd (patch) | |
tree | 73bb93aec300596fe0e8209e01d9db661b66fa80 /lib | |
parent | a428f7d1e03f62c47d6d7e0d48917ffb3291abce (diff) | |
download | nextcloud-server-de713967c0f109b674a96fddbb591a85b3e246bd.tar.gz nextcloud-server-de713967c0f109b674a96fddbb591a85b3e246bd.zip |
cleanup fileinfo creation
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Node/Folder.php | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index cc52908052d..db7d9fb49c0 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -32,11 +32,14 @@ namespace OC\Files\Node; use OC\DB\QueryBuilder\Literal; +use OC\Files\Mount\MountPoint; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; use OC\Files\Storage\Wrapper\Jail; +use OC\Files\Storage\Storage; use OCA\Files_Sharing\SharedStorage; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\Config\ICachedMountInfo; use OCP\Files\FileInfo; use OCP\Files\Mount\IMountPoint; @@ -227,6 +230,8 @@ class Folder extends Node implements \OCP\Files\Folder { $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%' . $query . '%')); } + // Limit+offset for queries without ordering + // // assume a setup where the root mount matches 15 items, // sub mount1 matches 7 items and mount2 matches 1 item // a search with (0..10) returns 10 results from root with internal offset 0 and limit 10 @@ -240,6 +245,8 @@ class Folder extends Node implements \OCP\Files\Folder { // (we don't know how many results the previous sub-query has skipped with it's own offset) // we instead discard the offset for the sub-queries and filter it afterwards and add the offset to limit. // this is sub-optimal but shouldn't hurt to much since large offsets are uncommon in practice + // + // All of this is only possible for queries without ordering $limitToHome = $query->limitToHome(); if ($limitToHome && count(explode('/', $this->path)) !== 3) { @@ -277,10 +284,7 @@ class Folder extends Node implements \OCP\Files\Folder { foreach ($results as $result) { if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { - $result['internalPath'] = $result['path']; - $result['path'] = substr($result['path'], $internalRootLength); - $result['storage'] = $storage; - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); + $files[] = $this->cacheEntryToFileInfo($mount, '', $internalPath, $result); } } @@ -312,11 +316,7 @@ class Folder extends Node implements \OCP\Files\Folder { $subQueryLimit -= $count; foreach ($results as $result) { - $result['internalPath'] = $result['path']; - $result['path'] = $relativeMountPoint . $result['path']; - $result['storage'] = $storage; - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, - $result['internalPath'], $result, $mount); + $files[] = $this->cacheEntryToFileInfo($mount, $relativeMountPoint, '', $result); } } } @@ -327,6 +327,13 @@ class Folder extends Node implements \OCP\Files\Folder { }, $files); } + private function cacheEntryToFileInfo(IMountPoint $mount, string $appendRoot, string $trimRoot, ICacheEntry $cacheEntry): FileInfo { + $trimLength = strlen($trimRoot); + $cacheEntry['internalPath'] = $cacheEntry['path']; + $cacheEntry['path'] = $appendRoot . substr($cacheEntry['path'], $trimLength); + return new \OC\Files\FileInfo($this->path . '/' . $cacheEntry['path'], $mount->getStorage(), $cacheEntry['internalPath'], $cacheEntry, $mount); + } + /** * search for files by mimetype * |