From d729daafc39af6c2be881aa402f6204de1dc846b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 14 Aug 2023 21:12:12 +0200 Subject: [PATCH] add IFileInfo::getParentId Signed-off-by: Robin Appelman --- apps/files_trashbin/lib/Trash/TrashItem.php | 4 ++++ lib/private/Files/FileInfo.php | 4 ++++ lib/private/Files/Node/LazyFolder.php | 7 +++++++ lib/private/Files/Node/Node.php | 15 ++++++++------- lib/public/Files/FileInfo.php | 9 +++++++++ 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/apps/files_trashbin/lib/Trash/TrashItem.php b/apps/files_trashbin/lib/Trash/TrashItem.php index 29de0a2ed5a81..3bfc905d3a163 100644 --- a/apps/files_trashbin/lib/Trash/TrashItem.php +++ b/apps/files_trashbin/lib/Trash/TrashItem.php @@ -186,4 +186,8 @@ public function getCreationTime(): int { public function getUploadTime(): int { return $this->fileInfo->getUploadTime(); } + + public function getParentId(): int { + return $this->fileInfo->getParentId(); + } } diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php index 2b6b83a25462c..235656cb4988b 100644 --- a/lib/private/Files/FileInfo.php +++ b/lib/private/Files/FileInfo.php @@ -428,4 +428,8 @@ public function getCreationTime(): int { public function getUploadTime(): int { return (int) $this->data['upload_time']; } + + public function getParentId(): int { + return $this->data['parent'] ?? -1; + } } diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index c307b55b5bc65..026a16060c4b2 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -551,4 +551,11 @@ public function getUploadTime(): int { public function getRelativePath($path) { return PathHelper::getRelativePath($this->getPath(), $path); } + + public function getParentId(): int { + if (isset($this->data['parent'])) { + return $this->data['parent']; + } + return $this->__call(__FUNCTION__, func_get_args()); + } } diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 0318ae47784c9..bc96a116da726 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -59,10 +59,7 @@ class Node implements INode { protected ?FileInfo $fileInfo; - /** - * @var Node|null - */ - protected $parent; + protected ?INode $parent; private bool $infoHasSubMountsIncluded; @@ -300,13 +297,13 @@ public function getParent(): INode|IRootFolder { return $this->root; } + // gather the metadata we already know about our parent $parentData = [ 'path' => $newPath, + 'fileid' => $this->getFileInfo()->getParentId(), ]; - if ($this->fileInfo instanceof \OC\Files\FileInfo && isset($this->fileInfo['parent'])) { - $parentData['fileid'] = $this->fileInfo['parent']; - } + // and create lazy folder with it instead of always querying $this->parent = new LazyFolder(function () use ($newPath) { return $this->root->get($newPath); }, $parentData); @@ -486,4 +483,8 @@ public function getCreationTime(): int { public function getUploadTime(): int { return $this->getFileInfo()->getUploadTime(); } + + public function getParentId(): int { + return $this->fileInfo->getParentId(); + } } diff --git a/lib/public/Files/FileInfo.php b/lib/public/Files/FileInfo.php index 83ae4adef9204..89637c5807660 100644 --- a/lib/public/Files/FileInfo.php +++ b/lib/public/Files/FileInfo.php @@ -299,4 +299,13 @@ public function getCreationTime(): int; * @since 18.0.0 */ public function getUploadTime(): int; + + /** + * Get the fileid or the parent folder + * or -1 if this item has no parent folder (because it is the root) + * + * @return int + * @since 28.0.1 + */ + public function getParentId(): int; }