From dcd9fd97cf1cdf020c6855ecb1b7da27f87ce14e 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 --- lib/private/Files/FileInfo.php | 4 ++++ lib/private/Files/Node/Node.php | 11 ++++------- lib/public/Files/FileInfo.php | 9 +++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) 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/Node.php b/lib/private/Files/Node/Node.php index 0318ae47784c9..e5bd6221e77d6 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->fileInfo->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); 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; }