]> source.dussan.org Git - nextcloud-server.git/commitdiff
Read notes from share already loaded into memory
authorDariusz Olszewski <starypatyk@users.noreply.github.com>
Fri, 7 Oct 2022 21:24:12 +0000 (23:24 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Fri, 14 Oct 2022 13:38:39 +0000 (13:38 +0000)
Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
apps/dav/lib/Connector/Sabre/Node.php
apps/files_sharing/lib/MountProvider.php

index 5fb811ad1ab155fd42f233dc71160dfc6979596f..e1cbdeac7e0d2519590a001481d3d1a0c5604a53 100644 (file)
@@ -355,23 +355,19 @@ abstract class Node implements \Sabre\DAV\INode {
                        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 '';
        }
 
index 954c9cf70e6cba78cfd7740b784e27ff06f3e055..a9705e94906c754605d557408203ca9d2f53d5b6 100644 (file)
@@ -229,6 +229,13 @@ class MountProvider implements IMountProvider {
                                ->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