Skip to content

Commit 0e31a45

Browse files
Carl Schwansusnux
authored andcommitted
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 d55d841 commit 0e31a45

7 files changed

Lines changed: 35 additions & 28 deletions

File tree

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

Lines changed: 8 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;
@@ -46,7 +47,9 @@ class Directory extends Node implements
4647
\Sabre\DAV\IQuota,
4748
\Sabre\DAV\IMoveTarget,
4849
\Sabre\DAV\ICopyTarget,
49-
INodeByPath {
50+
INodeByPath,
51+
ICacheableDirectory
52+
{
5053
/**
5154
* Cached directory content
5255
* @var FileInfo[]
@@ -574,4 +577,8 @@ public function getNodeForPath($path): INode {
574577

575578
return $node;
576579
}
580+
581+
public function getCacheableDirectories(): array {
582+
return [$this->getNode()];
583+
}
577584
}

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;
@@ -239,12 +237,10 @@ public function propFind($path, PropFind $propFind): void {
239237
}
240238

241239
$node = $this->tree->getNodeForPath($path);
242-
if (($node instanceof Directory) && $propFind->getDepth() !== 0) {
243-
$this->cacheDirectory($path, $node->getNode());
244-
} else if ($node instanceof TrashRoot) {
245-
$trashNodes = $node->getTrashRoots();
246-
foreach ($trashNodes as $trashNode) {
247-
$this->cacheDirectory($path, $trashNode);
240+
if (($node instanceof ICacheableDirectory) && $propFind->getDepth() !== 0) {
241+
$directoriesToPrefetch = $node->getCacheableDirectories();
242+
foreach ($directoriesToPrefetch as $directory) {
243+
$this->cacheDirectory($path, $directory);
248244
}
249245
}
250246

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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +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 {
27-
private ?Folder $trashFilesRoot = null;
28-
23+
class TrashRoot implements ICollection, ICacheableDirectory {
2924
public function __construct(
3025
private IUser $user,
3126
private ITrashManager $trashManager,
@@ -109,7 +104,7 @@ public function getLastModified(): int {
109104
/**
110105
* @return Folder[]
111106
*/
112-
public function getTrashRoots(): array {
113-
return $this->trashManager->getTrashRootsForUser($this->user);
107+
public function getCacheableDirectories(): array {
108+
return $this->trashManager->getCacheableRootsForUser($this->user);
114109
}
115110
}

apps/files_trashbin/lib/Trash/ITrashBackend.php

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

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

apps/files_trashbin/lib/Trash/ITrashManager.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,4 @@ public function pauseTrash();
4141
* @since 15.0.0
4242
*/
4343
public function resumeTrash();
44-
45-
/**
46-
* @since 32.0.0
47-
*/
48-
public function getTrashRootsForUser(IUser $user): array;
4944
}

apps/files_trashbin/lib/Trash/TrashManager.php

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

121-
public function getTrashRootsForUser(IUser $user): array {
122-
return array_reduce($this->getBackends(), function (array $items, ITrashBackend $backend) use ($user) {
123-
return array_merge($items, $backend->getTrashRootsForUser($user));
124-
}, []);
121+
public function getCacheableRootsForUser(IUser $user): array {
122+
return array_reduce($this->getBackends(),
123+
fn (array $items, ITrashBackend $backend) => array_merge($items, $backend->getCacheableRootsForUser($user)), []);
125124
}
126125
}

0 commit comments

Comments
 (0)