Skip to content

Commit 992b5b7

Browse files
committed
only fetch the data for mounts inside a folder when needed
for most operations we don't actually care about any mounts inside a folder, only for metadata that needs to propagate across storage boundaries (size, etag, mtime) do we need all the submount info. By only loading this data when needed we can save a bunch of storage setup in a number of cases Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 7341d33 commit 992b5b7

File tree

5 files changed

+50
-37
lines changed

5 files changed

+50
-37
lines changed

lib/private/Files/Node/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class File extends Node implements \OCP\Files\File {
3737
* Creates a Folder that represents a non-existing path
3838
*
3939
* @param string $path path
40-
* @return string non-existing node class
40+
* @return NonExistingFile non-existing node
4141
*/
4242
protected function createNonExistingNode($path) {
4343
return new NonExistingFile($this->root, $this->view, $path);

lib/private/Files/Node/Folder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Folder extends Node implements \OCP\Files\Folder {
5454
* Creates a Folder that represents a non-existing path
5555
*
5656
* @param string $path path
57-
* @return string non-existing node class
57+
* @return NonExistingFolder non-existing node
5858
*/
5959
protected function createNonExistingNode($path) {
6060
return new NonExistingFolder($this->root, $this->view, $path);
@@ -98,7 +98,7 @@ public function isSubNode($node) {
9898
* @throws \OCP\Files\NotFoundException
9999
*/
100100
public function getDirectoryListing() {
101-
$folderContent = $this->view->getDirectoryContent($this->path, '', $this->getFileInfo());
101+
$folderContent = $this->view->getDirectoryContent($this->path, '', $this->getFileInfo(false));
102102

103103
return array_map(function (FileInfo $info) {
104104
if ($info->getMimetype() === FileInfo::MIMETYPE_FOLDER) {
@@ -114,15 +114,15 @@ public function getDirectoryListing() {
114114
* @param FileInfo $info
115115
* @return File|Folder
116116
*/
117-
protected function createNode($path, FileInfo $info = null) {
117+
protected function createNode($path, FileInfo $info = null, bool $infoHasSubMountsIncluded = true) {
118118
if (is_null($info)) {
119119
$isDir = $this->view->is_dir($path);
120120
} else {
121121
$isDir = $info->getType() === FileInfo::TYPE_FOLDER;
122122
}
123123
$parent = dirname($path) === $this->getPath() ? $this : null;
124124
if ($isDir) {
125-
return new Folder($this->root, $this->view, $path, $info, $parent);
125+
return new Folder($this->root, $this->view, $path, $info, $parent, $infoHasSubMountsIncluded);
126126
} else {
127127
return new File($this->root, $this->view, $path, $info, $parent);
128128
}

lib/private/Files/Node/Node.php

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,35 @@ class Node implements \OCP\Files\Node {
5656
*/
5757
protected $path;
5858

59-
/**
60-
* @var \OCP\Files\FileInfo
61-
*/
62-
protected $fileInfo;
59+
protected ?FileInfo $fileInfo;
6360

6461
/**
6562
* @var Node|null
6663
*/
6764
protected $parent;
6865

66+
private bool $infoHasSubMountsIncluded;
67+
6968
/**
7069
* @param \OC\Files\View $view
7170
* @param \OCP\Files\IRootFolder $root
7271
* @param string $path
7372
* @param FileInfo $fileInfo
7473
*/
75-
public function __construct($root, $view, $path, $fileInfo = null, ?Node $parent = null) {
74+
public function __construct($root, $view, $path, $fileInfo = null, ?Node $parent = null, bool $infoHasSubMountsIncluded = true) {
7675
$this->view = $view;
7776
$this->root = $root;
7877
$this->path = $path;
7978
$this->fileInfo = $fileInfo;
8079
$this->parent = $parent;
80+
$this->infoHasSubMountsIncluded = $infoHasSubMountsIncluded;
8181
}
8282

8383
/**
8484
* Creates a Node of the same type that represents a non-existing path
8585
*
8686
* @param string $path path
87-
* @return string non-existing node class
87+
* @return Node non-existing node
8888
* @throws \Exception
8989
*/
9090
protected function createNonExistingNode($path) {
@@ -98,17 +98,23 @@ protected function createNonExistingNode($path) {
9898
* @throws InvalidPathException
9999
* @throws NotFoundException
100100
*/
101-
public function getFileInfo() {
101+
public function getFileInfo(bool $includeMountPoint = true) {
102102
if (!$this->fileInfo) {
103103
if (!Filesystem::isValidPath($this->path)) {
104104
throw new InvalidPathException();
105105
}
106-
$fileInfo = $this->view->getFileInfo($this->path);
106+
$fileInfo = $this->view->getFileInfo($this->path, $includeMountPoint);
107+
$this->infoHasSubMountsIncluded = $includeMountPoint;
107108
if ($fileInfo instanceof FileInfo) {
108109
$this->fileInfo = $fileInfo;
109110
} else {
110111
throw new NotFoundException();
111112
}
113+
} elseif ($includeMountPoint && !$this->infoHasSubMountsIncluded && $this instanceof Folder) {
114+
if ($this->fileInfo instanceof \OC\Files\FileInfo) {
115+
$this->view->addSubMounts($this->fileInfo);
116+
}
117+
$this->infoHasSubMountsIncluded = true;
112118
}
113119
return $this->fileInfo;
114120
}
@@ -179,7 +185,7 @@ public function getPath() {
179185
* @return string
180186
*/
181187
public function getInternalPath() {
182-
return $this->getFileInfo()->getInternalPath();
188+
return $this->getFileInfo(false)->getInternalPath();
183189
}
184190

185191
/**
@@ -188,7 +194,7 @@ public function getInternalPath() {
188194
* @throws NotFoundException
189195
*/
190196
public function getId() {
191-
return $this->getFileInfo()->getId();
197+
return $this->getFileInfo(false)->getId();
192198
}
193199

194200
/**
@@ -232,7 +238,7 @@ public function getEtag() {
232238
* @throws NotFoundException
233239
*/
234240
public function getPermissions() {
235-
return $this->getFileInfo()->getPermissions();
241+
return $this->getFileInfo(false)->getPermissions();
236242
}
237243

238244
/**
@@ -241,7 +247,7 @@ public function getPermissions() {
241247
* @throws NotFoundException
242248
*/
243249
public function isReadable() {
244-
return $this->getFileInfo()->isReadable();
250+
return $this->getFileInfo(false)->isReadable();
245251
}
246252

247253
/**
@@ -250,7 +256,7 @@ public function isReadable() {
250256
* @throws NotFoundException
251257
*/
252258
public function isUpdateable() {
253-
return $this->getFileInfo()->isUpdateable();
259+
return $this->getFileInfo(false)->isUpdateable();
254260
}
255261

256262
/**
@@ -259,7 +265,7 @@ public function isUpdateable() {
259265
* @throws NotFoundException
260266
*/
261267
public function isDeletable() {
262-
return $this->getFileInfo()->isDeletable();
268+
return $this->getFileInfo(false)->isDeletable();
263269
}
264270

265271
/**
@@ -268,7 +274,7 @@ public function isDeletable() {
268274
* @throws NotFoundException
269275
*/
270276
public function isShareable() {
271-
return $this->getFileInfo()->isShareable();
277+
return $this->getFileInfo(false)->isShareable();
272278
}
273279

274280
/**
@@ -277,7 +283,7 @@ public function isShareable() {
277283
* @throws NotFoundException
278284
*/
279285
public function isCreatable() {
280-
return $this->getFileInfo()->isCreatable();
286+
return $this->getFileInfo(false)->isCreatable();
281287
}
282288

283289
/**
@@ -328,42 +334,42 @@ public function isValidPath($path) {
328334
}
329335

330336
public function isMounted() {
331-
return $this->getFileInfo()->isMounted();
337+
return $this->getFileInfo(false)->isMounted();
332338
}
333339

334340
public function isShared() {
335-
return $this->getFileInfo()->isShared();
341+
return $this->getFileInfo(false)->isShared();
336342
}
337343

338344
public function getMimeType() {
339-
return $this->getFileInfo()->getMimetype();
345+
return $this->getFileInfo(false)->getMimetype();
340346
}
341347

342348
public function getMimePart() {
343-
return $this->getFileInfo()->getMimePart();
349+
return $this->getFileInfo(false)->getMimePart();
344350
}
345351

346352
public function getType() {
347-
return $this->getFileInfo()->getType();
353+
return $this->getFileInfo(false)->getType();
348354
}
349355

350356
public function isEncrypted() {
351-
return $this->getFileInfo()->isEncrypted();
357+
return $this->getFileInfo(false)->isEncrypted();
352358
}
353359

354360
public function getMountPoint() {
355-
return $this->getFileInfo()->getMountPoint();
361+
return $this->getFileInfo(false)->getMountPoint();
356362
}
357363

358364
public function getOwner() {
359-
return $this->getFileInfo()->getOwner();
365+
return $this->getFileInfo(false)->getOwner();
360366
}
361367

362368
public function getChecksum() {
363369
}
364370

365371
public function getExtension(): string {
366-
return $this->getFileInfo()->getExtension();
372+
return $this->getFileInfo(false)->getExtension();
367373
}
368374

369375
/**

lib/private/Files/Node/Root.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ public function get($path) {
202202
$path = $this->normalizePath($path);
203203
if ($this->isValidPath($path)) {
204204
$fullPath = $this->getFullPath($path);
205-
$fileInfo = $this->view->getFileInfo($fullPath);
205+
$fileInfo = $this->view->getFileInfo($fullPath, false);
206206
if ($fileInfo) {
207-
return $this->createNode($fullPath, $fileInfo);
207+
return $this->createNode($fullPath, $fileInfo, false);
208208
} else {
209209
throw new NotFoundException($path);
210210
}

lib/private/Files/View.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,11 +1412,7 @@ public function getFileInfo($path, $includeMountPoints = true) {
14121412
if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') {
14131413
//add the sizes of other mount points to the folder
14141414
$extOnly = ($includeMountPoints === 'ext');
1415-
$mounts = Filesystem::getMountManager()->findIn($path);
1416-
$info->setSubMounts(array_filter($mounts, function (IMountPoint $mount) use ($extOnly) {
1417-
$subStorage = $mount->getStorage();
1418-
return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage);
1419-
}));
1415+
$this->addSubMounts($info, $extOnly);
14201416
}
14211417
}
14221418

@@ -1428,6 +1424,17 @@ public function getFileInfo($path, $includeMountPoints = true) {
14281424
return false;
14291425
}
14301426

1427+
/**
1428+
* Extend a FileInfo that was previously requested with `$includeMountPoints = false` to include the sub mounts
1429+
*/
1430+
public function addSubMounts(FileInfo $info, $extOnly = false): void {
1431+
$mounts = Filesystem::getMountManager()->findIn($info->getPath());
1432+
$info->setSubMounts(array_filter($mounts, function (IMountPoint $mount) use ($extOnly) {
1433+
$subStorage = $mount->getStorage();
1434+
return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage);
1435+
}));
1436+
}
1437+
14311438
/**
14321439
* get the content of a directory
14331440
*

0 commit comments

Comments
 (0)