Skip to content

Commit e574092

Browse files
author
Carl Schwan
committed
fix(trashbin): Fix n+1 issue in propfind in trash root
CustomPropertiesBackend is already able to cache the custom properties of a folder content. But the trash root is not a Directory but instead just a ICollection, so extend CacheEntry to also handle a TrashEntry. Signed-off-by: Carl Schwan <carl.schwan@nextclound.com>
1 parent 6e9d48b commit e574092

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

apps/dav/lib/DAV/CustomPropertiesBackend.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\DAV\CalDAV\DefaultCalendarValidator;
1414
use OCA\DAV\Connector\Sabre\Directory;
1515
use OCA\DAV\Connector\Sabre\FilesPlugin;
16+
use OCA\Files_Trashbin\Sabre\TrashRoot;
1617
use OCP\DB\QueryBuilder\IQueryBuilder;
1718
use OCP\IDBConnection;
1819
use OCP\IUser;
@@ -220,7 +221,7 @@ public function propFind($path, PropFind $propFind) {
220221
}
221222

222223
$node = $this->tree->getNodeForPath($path);
223-
if ($node instanceof Directory && $propFind->getDepth() !== 0) {
224+
if (($node instanceof Directory || $node instanceof TrashRoot) && $propFind->getDepth() !== 0) {
224225
$this->cacheDirectory($path, $node);
225226
}
226227

@@ -344,18 +345,22 @@ private function getPublishedProperties(string $path, array $requestedProperties
344345
/**
345346
* prefetch all user properties in a directory
346347
*/
347-
private function cacheDirectory(string $path, Directory $node): void {
348+
private function cacheDirectory(string $path, Directory|TrashRoot $node): void {
349+
$internalNode = $node->getNode();
350+
if (!$internalNode) {
351+
return;
352+
}
353+
348354
$prefix = ltrim($path . '/', '/');
349355
$query = $this->connection->getQueryBuilder();
350356
$query->select('name', 'p.propertypath', 'p.propertyname', 'p.propertyvalue', 'p.valuetype')
351357
->from('filecache', 'f')
352-
->hintShardKey('storage', $node->getNode()->getMountPoint()->getNumericStorageId())
358+
->hintShardKey('storage', $internalNode->getMountPoint()->getNumericStorageId())
353359
->leftJoin('f', 'properties', 'p', $query->expr()->eq('p.propertypath', $query->func()->concat(
354360
$query->createNamedParameter($prefix),
355361
'f.name'
356-
)),
357-
)
358-
->where($query->expr()->eq('parent', $query->createNamedParameter($node->getInternalFileId(), IQueryBuilder::PARAM_INT)))
362+
)))
363+
->where($query->expr()->eq('parent', $query->createNamedParameter($internalNode->getId(), IQueryBuilder::PARAM_INT)))
359364
->andWhere($query->expr()->orX(
360365
$query->expr()->eq('p.userid', $query->createNamedParameter($this->user->getUID())),
361366
$query->expr()->isNull('p.userid'),

apps/files_trashbin/lib/Sabre/TrashRoot.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
use OCA\Files_Trashbin\Trash\ITrashManager;
1414
use OCA\Files_Trashbin\Trashbin;
1515
use OCP\Files\FileInfo;
16+
use OCP\Files\Folder;
17+
use OCP\Files\IRootFolder;
18+
use OCP\Files\NotFoundException;
19+
use OCP\Files\NotPermittedException;
1620
use OCP\IUser;
21+
use OCP\Server;
1722
use Sabre\DAV\Exception\Forbidden;
1823
use Sabre\DAV\Exception\NotFound;
1924
use Sabre\DAV\ICollection;
@@ -90,4 +95,26 @@ public function childExists($name): bool {
9095
public function getLastModified(): int {
9196
return 0;
9297
}
98+
99+
public function getNode(): ?Folder {
100+
static $trashFilesRoot = null;
101+
if ($trashFilesRoot === null) {
102+
$rootFolder = Server::get(IRootFolder::class);
103+
$userRoot = $rootFolder->getUserFolder($this->user->getUID())->getParent();
104+
try {
105+
/** @var Folder $trashRoot */
106+
$trashRoot = $userRoot->get('files_trashbin');
107+
/** @var Folder $trashFilesRoot */
108+
$trashFilesRoot = $trashRoot->get('files');
109+
} catch (NotFoundException|NotPermittedException) {
110+
return null;
111+
}
112+
}
113+
114+
return $trashFilesRoot;
115+
}
116+
117+
public function getInternalFileId() {
118+
return $this->getNode()->getId();
119+
}
93120
}

0 commit comments

Comments
 (0)