From 6119604f7153d0786ac0c8c2519a2dad892ab127 Mon Sep 17 00:00:00 2001 From: Dariusz Olszewski Date: Fri, 7 Oct 2022 23:24:12 +0200 Subject: [PATCH 1/2] Read notes from share already loaded into memory Signed-off-by: Dariusz Olszewski --- apps/dav/lib/Connector/Sabre/Node.php | 26 ++++++++++-------------- apps/files_sharing/lib/MountProvider.php | 7 +++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/Node.php b/apps/dav/lib/Connector/Sabre/Node.php index 5fb811ad1ab15..e1cbdeac7e0d2 100644 --- a/apps/dav/lib/Connector/Sabre/Node.php +++ b/apps/dav/lib/Connector/Sabre/Node.php @@ -355,23 +355,19 @@ public function getNoteFromShare($user) { return ''; } - $types = [ - IShare::TYPE_USER, - IShare::TYPE_GROUP, - IShare::TYPE_CIRCLE, - IShare::TYPE_ROOM - ]; - - foreach ($types as $shareType) { - $shares = $this->shareManager->getSharedWith($user, $shareType, $this, -1); - foreach ($shares as $share) { - $note = $share->getNote(); - if ($share->getShareOwner() !== $user && !empty($note)) { - return $note; - } - } + // Retrieve note from the share object already loaded into + // memory, to avoid additional database queries. + $storage = $this->getNode()->getStorage(); + if (!$storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) { + return ''; } + /** @var \OCA\Files_Sharing\SharedStorage $storage */ + $share = $storage->getShare(); + $note = $share->getNote(); + if ($share->getShareOwner() !== $user && !empty($note)) { + return $note; + } return ''; } diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 954c9cf70e6cb..a9705e94906c7 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -229,6 +229,13 @@ private function buildSuperShares(array $allShares, \OCP\IUser $user) { ->setShareType($shares[0]->getShareType()) ->setTarget($shares[0]->getTarget()); + // Gather notes from all the shares. + // Since these are readly available here, storing them + // enables the DAV FilesPlugin to avoid executing many + // DB queries to retrieve the same information. + $allNotes = implode("\n", array_map(function ($sh) { return $sh->getNote(); }, $shares)); + $superShare->setNote($allNotes); + // use most permissive permissions // this covers the case where there are multiple shares for the same // file e.g. from different groups and different permissions From 52a5d0cea6b065d6d466bf305f1e97c17c64af31 Mon Sep 17 00:00:00 2001 From: Dariusz Olszewski Date: Mon, 10 Oct 2022 21:03:28 +0200 Subject: [PATCH 2/2] Review comment - remove redundant empty() call Signed-off-by: Dariusz Olszewski --- apps/dav/lib/Connector/Sabre/Node.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dav/lib/Connector/Sabre/Node.php b/apps/dav/lib/Connector/Sabre/Node.php index e1cbdeac7e0d2..1e32e74c325b6 100644 --- a/apps/dav/lib/Connector/Sabre/Node.php +++ b/apps/dav/lib/Connector/Sabre/Node.php @@ -365,7 +365,7 @@ public function getNoteFromShare($user) { $share = $storage->getShare(); $note = $share->getNote(); - if ($share->getShareOwner() !== $user && !empty($note)) { + if ($share->getShareOwner() !== $user) { return $note; } return '';