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; }