summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2022-08-25 08:47:04 +0200
committerGitHub <noreply@github.com>2022-08-25 08:47:04 +0200
commit06340b6672ea8019e8dc9fff5e87d2edb8a3ac17 (patch)
treeee070dba8dfdadc25cc04888b36e016e529e5720 /lib
parent405b5de6fa408841fb242d77ca7d37c1fb87efa4 (diff)
parent83b1415906babd3ad521055dd2142fed09250ca6 (diff)
downloadnextcloud-server-06340b6672ea8019e8dc9fff5e87d2edb8a3ac17.tar.gz
nextcloud-server-06340b6672ea8019e8dc9fff5e87d2edb8a3ac17.zip
Merge pull request #33602 from nextcloud/perf/parent-node
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Node/Folder.php14
-rw-r--r--lib/private/Files/Node/Node.php21
-rw-r--r--lib/private/Preview/ProviderV1Adapter.php2
3 files changed, 25 insertions, 12 deletions
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index 42562c99bcb..81ca7e254d9 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -101,9 +101,9 @@ class Folder extends Node implements \OCP\Files\Folder {
return array_map(function (FileInfo $info) {
if ($info->getMimetype() === FileInfo::MIMETYPE_FOLDER) {
- return new Folder($this->root, $this->view, $info->getPath(), $info);
+ return new Folder($this->root, $this->view, $info->getPath(), $info, $this);
} else {
- return new File($this->root, $this->view, $info->getPath(), $info);
+ return new File($this->root, $this->view, $info->getPath(), $info, $this);
}
}, $folderContent);
}
@@ -119,10 +119,11 @@ class Folder extends Node implements \OCP\Files\Folder {
} else {
$isDir = $info->getType() === FileInfo::TYPE_FOLDER;
}
+ $parent = dirname($path) === $this->getPath() ? $this : null;
if ($isDir) {
- return new Folder($this->root, $this->view, $path, $info);
+ return new Folder($this->root, $this->view, $path, $info, $parent);
} else {
- return new File($this->root, $this->view, $path, $info);
+ return new File($this->root, $this->view, $path, $info, $parent);
}
}
@@ -163,7 +164,8 @@ class Folder extends Node implements \OCP\Files\Folder {
if (!$this->view->mkdir($fullPath)) {
throw new NotPermittedException('Could not create folder');
}
- $node = new Folder($this->root, $this->view, $fullPath);
+ $parent = dirname($fullPath) === $this->getPath() ? $this : null;
+ $node = new Folder($this->root, $this->view, $fullPath, null, $parent);
$this->sendHooks(['postWrite', 'postCreate'], [$node]);
return $node;
} else {
@@ -193,7 +195,7 @@ class Folder extends Node implements \OCP\Files\Folder {
if ($result === false) {
throw new NotPermittedException('Could not create path');
}
- $node = new File($this->root, $this->view, $fullPath);
+ $node = new File($this->root, $this->view, $fullPath, null, $this);
$this->sendHooks(['postWrite', 'postCreate'], [$node]);
return $node;
}
diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php
index c8975154059..bfa4d6861ea 100644
--- a/lib/private/Files/Node/Node.php
+++ b/lib/private/Files/Node/Node.php
@@ -62,16 +62,22 @@ class Node implements \OCP\Files\Node {
protected $fileInfo;
/**
+ * @var Node|null
+ */
+ protected $parent;
+
+ /**
* @param \OC\Files\View $view
* @param \OCP\Files\IRootFolder $root
* @param string $path
* @param FileInfo $fileInfo
*/
- public function __construct($root, $view, $path, $fileInfo = null) {
+ public function __construct($root, $view, $path, $fileInfo = null, ?Node $parent = null) {
$this->view = $view;
$this->root = $root;
$this->path = $path;
$this->fileInfo = $fileInfo;
+ $this->parent = $parent;
}
/**
@@ -278,11 +284,16 @@ class Node implements \OCP\Files\Node {
* @return Node
*/
public function getParent() {
- $newPath = dirname($this->path);
- if ($newPath === '' || $newPath === '.' || $newPath === '/') {
- return $this->root;
+ if ($this->parent === null) {
+ $newPath = dirname($this->path);
+ if ($newPath === '' || $newPath === '.' || $newPath === '/') {
+ return $this->root;
+ }
+
+ $this->parent = $this->root->get($newPath);
}
- return $this->root->get($newPath);
+
+ return $this->parent;
}
/**
diff --git a/lib/private/Preview/ProviderV1Adapter.php b/lib/private/Preview/ProviderV1Adapter.php
index 22db380d30d..5e50db9d8da 100644
--- a/lib/private/Preview/ProviderV1Adapter.php
+++ b/lib/private/Preview/ProviderV1Adapter.php
@@ -55,7 +55,7 @@ class ProviderV1Adapter implements IProviderV2 {
}
private function getViewAndPath(File $file) {
- $view = new View($file->getParent()->getPath());
+ $view = new View(dirname($file->getPath()));
$path = $file->getName();
return [$view, $path];