Skip to content

Commit 4d9b244

Browse files
author
Carl Schwan
committed
refactor(trash): Introduce ICacheableDirectory interface
That interface can be implemented by any ICollection that is based on one or multiple \OCP\Files\Folder to pre-fetch the custom properties. Signed-off-by: Carl Schwan <carl.schwan@nextclound.com>
1 parent 9f2660e commit 4d9b244

7 files changed

Lines changed: 33 additions & 26 deletions

File tree

apps/dav/lib/Connector/Sabre/Directory.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
1414
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
1515
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
16+
use OCA\DAV\DAV\ICacheableDirectory;
1617
use OCA\DAV\Storage\PublicShareWrapper;
1718
use OCP\App\IAppManager;
1819
use OCP\Constants;
@@ -39,7 +40,7 @@
3940
use Sabre\DAV\IFile;
4041
use Sabre\DAV\INode;
4142

42-
class Directory extends Node implements \Sabre\DAV\ICollection, \Sabre\DAV\IQuota, \Sabre\DAV\IMoveTarget, \Sabre\DAV\ICopyTarget {
43+
class Directory extends Node implements \Sabre\DAV\ICollection, \Sabre\DAV\IQuota, \Sabre\DAV\IMoveTarget, \Sabre\DAV\ICopyTarget, ICacheableDirectory {
4344
/**
4445
* Cached directory content
4546
* @var FileInfo[]
@@ -490,4 +491,8 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode) {
490491
public function getNode(): Folder {
491492
return $this->node;
492493
}
494+
495+
public function getCacheableDirectories(): array {
496+
return [$this->getNode()];
497+
}
493498
}

apps/dav/lib/DAV/CustomPropertiesBackend.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
use OCA\DAV\CalDAV\Trashbin\TrashbinHome;
2020
use OCA\DAV\Connector\Sabre\Directory;
2121
use OCA\DAV\Db\PropertyMapper;
22-
use OCA\DAV\Connector\Sabre\FilesPlugin;
23-
use OCA\Files_Trashbin\Sabre\TrashRoot;
2422
use OCP\DB\QueryBuilder\IQueryBuilder;
2523
use OCP\Files\Folder;
2624
use OCP\IDBConnection;
@@ -210,12 +208,10 @@ public function propFind($path, PropFind $propFind) {
210208
}
211209

212210
$node = $this->tree->getNodeForPath($path);
213-
if (($node instanceof Directory) && $propFind->getDepth() !== 0) {
214-
$this->cacheDirectory($path, $node->getNode());
215-
} else if ($node instanceof TrashRoot) {
216-
$trashNodes = $node->getTrashRoots();
217-
foreach ($trashNodes as $trashNode) {
218-
$this->cacheDirectory($path, $trashNode);
211+
if (($node instanceof ICacheableDirectory) && $propFind->getDepth() !== 0) {
212+
$directoriesToPrefetch = $node->getCacheableDirectories();
213+
foreach ($directoriesToPrefetch as $directory) {
214+
$this->cacheDirectory($path, $directory);
219215
}
220216
}
221217

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace OCA\DAV\DAV;
4+
5+
use OCP\Files\Folder;
6+
7+
interface ICacheableDirectory {
8+
/**
9+
* @return Folder[]
10+
*/
11+
public function getCacheableDirectories(): array;
12+
}

apps/files_trashbin/lib/Sabre/TrashRoot.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@
88
*/
99
namespace OCA\Files_Trashbin\Sabre;
1010

11+
use OCA\DAV\DAV\ICacheableDirectory;
1112
use OCA\Files_Trashbin\Service\ConfigService;
1213
use OCA\Files_Trashbin\Trash\ITrashItem;
1314
use OCA\Files_Trashbin\Trash\ITrashManager;
1415
use OCA\Files_Trashbin\Trashbin;
1516
use OCP\Files\FileInfo;
1617
use OCP\Files\Folder;
17-
use OCP\Files\IRootFolder;
18-
use OCP\Files\NotFoundException;
19-
use OCP\Files\NotPermittedException;
2018
use OCP\IUser;
21-
use OCP\Server;
2219
use Sabre\DAV\Exception\Forbidden;
2320
use Sabre\DAV\Exception\NotFound;
2421
use Sabre\DAV\ICollection;
2522

26-
class TrashRoot implements ICollection {
23+
class TrashRoot implements ICollection, ICacheableDirectory {
2724
private ?Folder $trashFilesRoot = null;
2825

2926
public function __construct(
@@ -100,7 +97,7 @@ public function getLastModified(): int {
10097
/**
10198
* @return Folder[]
10299
*/
103-
public function getTrashRoots(): array {
104-
return $this->trashManager->getTrashRootsForUser($this->user);
100+
public function getCacheableDirectories(): array {
101+
return $this->trashManager->getCacheableRootsForUser($this->user);
105102
}
106103
}

apps/files_trashbin/lib/Trash/ITrashBackend.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ public function moveToTrash(IStorage $storage, string $internalPath): bool;
6767
public function getTrashNodeById(IUser $user, int $fileId);
6868

6969
/**
70+
* Returns a non-exhaustive list of folder which can then be used to pre-fetch some metadata
71+
* * for the trash root.
72+
*
7073
* @return Folder[]
7174
* @since 32.0.0
7275
*/
73-
public function getTrashRootsForUser(IUser $user): array;
76+
public function getCacheableRootsForUser(IUser $user): array;
7477
}

apps/files_trashbin/lib/Trash/ITrashManager.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,4 @@ public function pauseTrash();
3838
* @since 15.0.0
3939
*/
4040
public function resumeTrash();
41-
42-
/**
43-
* @since 32.0.0
44-
*/
45-
public function getTrashRootsForUser(IUser $user): array;
4641
}

apps/files_trashbin/lib/Trash/TrashManager.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ public function resumeTrash() {
109109
$this->trashPaused = false;
110110
}
111111

112-
public function getTrashRootsForUser(IUser $user): array {
113-
return array_reduce($this->getBackends(), function (array $items, ITrashBackend $backend) use ($user) {
114-
return array_merge($items, $backend->getTrashRootsForUser($user));
115-
}, []);
112+
public function getCacheableRootsForUser(IUser $user): array {
113+
return array_reduce($this->getBackends(),
114+
fn (array $items, ITrashBackend $backend) => array_merge($items, $backend->getCacheableRootsForUser($user)), []);
116115
}
117116
}

0 commit comments

Comments
 (0)