diff --git a/apps/files_sharing/lib/External/Cache.php b/apps/files_sharing/lib/External/Cache.php index 027f682d81841..4e7a6e5195d03 100644 --- a/apps/files_sharing/lib/External/Cache.php +++ b/apps/files_sharing/lib/External/Cache.php @@ -48,4 +48,13 @@ public function getFolderContentsById($fileId) { } return $results; } + + #[Override] + public function iterateFolderContentsById(int $fileId, bool $includeMetadata = false, bool $sortByName = false): iterable { + $displayId = $this->cloudId->getDisplayId(); + foreach (parent::iterateFolderContentsById($fileI, $includeMetadata, $sortByName) as $entry) { + $entry['displayname_owner'] = $displayId; + yield $entry; + } + } } diff --git a/apps/files_trashbin/lib/Helper.php b/apps/files_trashbin/lib/Helper.php index 746832e9280cd..8f8d8c80ba493 100644 --- a/apps/files_trashbin/lib/Helper.php +++ b/apps/files_trashbin/lib/Helper.php @@ -41,7 +41,8 @@ public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDesc $internalPath = $mount->getInternalPath($absoluteDir); $extraData = Trashbin::getExtraData($user); - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); + $dirId = $storage->getCache()->getId($mount->getInternalPath($view->getAbsolutePath($dir))); + $dirContent = $storage->getCache()->iterateFolderContentsById($dirId); foreach ($dirContent as $entry) { $entryName = $entry->getName(); $name = $entryName; diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 6213b88fc17df..bd9d93adfc711 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -35,6 +35,7 @@ use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IDBConnection; use OCP\Util; +use Override; use Psr\Log\LoggerInterface; /** @@ -238,6 +239,33 @@ public function getFolderContentsById($fileId) { return []; } + #[Override] + public function iterateFolderContentsById(int $fileId, bool $includeMetadata = false, bool $sortByName = false): iterable { + if ($fileId < 1) { + return []; + } + + $query = $this->getQueryBuilder() + ->selectFileCache() + ->whereParent($fileId) + ->whereStorageId($this->getNumericStorageId()); + if ($includeMetadata === true) { + $metadataQuery = $query->selectMetadata(); + } + if ($sortByName) { + $query->orderBy('name', 'ASC'); + } + + $result = $query->executeQuery(); + foreach ($result->iterateAssociative() as $row) { + if ($includeMetadata === true) { + $row['metadata'] = $metadataQuery->extractMetadata($row)->asArray(); + } + yield self::cacheEntryFromData($row, $this->mimetypeLoader); + } + $result->closeCursor(); + } + /** * insert or update meta data for a file or folder * diff --git a/lib/private/Files/Cache/FailedCache.php b/lib/private/Files/Cache/FailedCache.php index 44c1016ca8ea6..3a679180cc0e2 100644 --- a/lib/private/Files/Cache/FailedCache.php +++ b/lib/private/Files/Cache/FailedCache.php @@ -59,6 +59,11 @@ public function getFolderContentsById($fileId) { return []; } + #[Override] + public function iterateFolderContentsById(int $fileId, bool $includeMetadata = false, bool $sortByName = false): iterable { + return []; + } + public function put($file, array $data) { } diff --git a/lib/private/Files/Cache/Watcher.php b/lib/private/Files/Cache/Watcher.php index 891fe762eb896..5bfb444544042 100644 --- a/lib/private/Files/Cache/Watcher.php +++ b/lib/private/Files/Cache/Watcher.php @@ -141,7 +141,7 @@ public function needsUpdate($path, $cachedData) { * @param string $path */ public function cleanFolder($path) { - $cachedContent = $this->cache->getFolderContents($path); + $cachedContent = $this->cache->iterateFolderContentsById($this->cache->getId($path)); foreach ($cachedContent as $entry) { if (!$this->storage->file_exists($entry['path'])) { $this->cache->remove($entry['path']); diff --git a/lib/private/Files/Cache/Wrapper/CacheWrapper.php b/lib/private/Files/Cache/Wrapper/CacheWrapper.php index bf23f1cc30ab0..7cb333ca3586b 100644 --- a/lib/private/Files/Cache/Wrapper/CacheWrapper.php +++ b/lib/private/Files/Cache/Wrapper/CacheWrapper.php @@ -110,6 +110,13 @@ public function getFolderContentsById($fileId) { return array_map([$this, 'formatCacheEntry'], $results); } + #[Override] + public function iterateFolderContentsById(int $fileId, bool $includeMetadata = false, bool $sortByName = false): iterable { + foreach ($this->getCache()->iterateFolderContentsById($fileId, $includeMetadata, $sortByName) as $entry) { + yield $this->formatCacheEntry($entry); + } + } + /** * insert or update meta data for a file or folder * diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index ce5fc5b1063ba..7858d59142eac 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -164,7 +164,7 @@ public function rmdir(string $path): bool { } private function rmObjects(ICacheEntry $entry): bool { - $children = $this->getCache()->getFolderContentsById($entry->getId()); + $children = $this->getCache()->iterateFolderContentsById($entry->getId()); foreach ($children as $child) { if ($child->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE) { if (!$this->rmObjects($child)) { @@ -263,7 +263,7 @@ public function opendir(string $path) { try { $files = []; - $folderContents = $this->getCache()->getFolderContents($path); + $folderContents = $this->getCache()->iterateFolderContentsById($this->getCache()->getId($path), false, true); foreach ($folderContents as $file) { $files[] = $file['name']; } diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index c0325d9aa2887..b8ad1618ad50e 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1507,7 +1507,7 @@ public function getDirectoryContent($directory, $mimetype_filter = '', ?\OCP\Fil } $folderId = $data->getId(); - $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter + $contents = $cache->iterateFolderContentsById($folderId, false, true); // TODO Mimetype filter $sharingDisabled = \OCP\Util::isSharingDisabledForUser(); $permissionsMask = ~\OCP\Constants::PERMISSION_SHARE; diff --git a/lib/private/Lockdown/Filesystem/NullCache.php b/lib/private/Lockdown/Filesystem/NullCache.php index 5a27c5d5c6e9e..e617cf51ca955 100644 --- a/lib/private/Lockdown/Filesystem/NullCache.php +++ b/lib/private/Lockdown/Filesystem/NullCache.php @@ -49,6 +49,11 @@ public function getFolderContentsById($fileId) { return []; } + #[Override] + public function iterateFolderContentsById(int $fileId, bool $includeMetadata = false, bool $sortByName = false): iterable { + return []; + } + public function put($file, array $data) { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } diff --git a/lib/public/Files/Cache/ICache.php b/lib/public/Files/Cache/ICache.php index cd610b155454b..4fdf266d61cbe 100644 --- a/lib/public/Files/Cache/ICache.php +++ b/lib/public/Files/Cache/ICache.php @@ -82,6 +82,16 @@ public function getFolderContents($folder); */ public function getFolderContentsById($fileId); + /** + * Get an iterator on files stored in folder + * + * Only returns files one level deep, no recursion + * + * @return iterable + * @since 34.0.0 + */ + public function iterateFolderContentsById(int $fileId, bool $includeMetadata = false, bool $sortByName = false): iterable; + /** * store meta data for a file or folder * This will automatically call either insert or update depending on if the file exists