Skip to content

Commit fb92a7a

Browse files
Carl SchwanCarlSchwan
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 8495993 commit fb92a7a

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
@@ -14,6 +14,7 @@
1414
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
1515
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
1616
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
17+
use OCA\DAV\DAV\ICacheableDirectory;
1718
use OCA\DAV\Storage\PublicShareWrapper;
1819
use OCP\App\IAppManager;
1920
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[]
@@ -563,4 +566,8 @@ public function getNodeForPath($path): INode {
563566

564567
return $node;
565568
}
569+
570+
public function getCacheableDirectories(): array {
571+
return [$this->getNode()];
572+
}
566573
}

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;
@@ -211,12 +209,10 @@ public function propFind($path, PropFind $propFind): void {
211209
}
212210

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

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,
@@ -100,7 +95,7 @@ public function getLastModified(): int {
10095
/**
10196
* @return Folder[]
10297
*/
103-
public function getTrashRoots(): array {
104-
return $this->trashManager->getTrashRootsForUser($this->user);
98+
public function getCacheableDirectories(): array {
99+
return $this->trashManager->getCacheableRootsForUser($this->user);
105100
}
106101
}

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)