Skip to content

Commit 95d45c2

Browse files
authored
Merge pull request #34471 from starypatyk/dav_read_share_notes
Reduce number of database queries during WebDAV propfind request
2 parents 2cef188 + c0bd748 commit 95d45c2

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -355,23 +355,19 @@ public function getNoteFromShare($user) {
355355
return '';
356356
}
357357

358-
$types = [
359-
IShare::TYPE_USER,
360-
IShare::TYPE_GROUP,
361-
IShare::TYPE_CIRCLE,
362-
IShare::TYPE_ROOM
363-
];
364-
365-
foreach ($types as $shareType) {
366-
$shares = $this->shareManager->getSharedWith($user, $shareType, $this, -1);
367-
foreach ($shares as $share) {
368-
$note = $share->getNote();
369-
if ($share->getShareOwner() !== $user && !empty($note)) {
370-
return $note;
371-
}
372-
}
358+
// Retrieve note from the share object already loaded into
359+
// memory, to avoid additional database queries.
360+
$storage = $this->getNode()->getStorage();
361+
if (!$storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) {
362+
return '';
373363
}
364+
/** @var \OCA\Files_Sharing\SharedStorage $storage */
374365

366+
$share = $storage->getShare();
367+
$note = $share->getNote();
368+
if ($share->getShareOwner() !== $user) {
369+
return $note;
370+
}
375371
return '';
376372
}
377373

apps/files_sharing/lib/MountProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ private function buildSuperShares(array $allShares, \OCP\IUser $user) {
229229
->setShareType($shares[0]->getShareType())
230230
->setTarget($shares[0]->getTarget());
231231

232+
// Gather notes from all the shares.
233+
// Since these are readly available here, storing them
234+
// enables the DAV FilesPlugin to avoid executing many
235+
// DB queries to retrieve the same information.
236+
$allNotes = implode("\n", array_map(function ($sh) { return $sh->getNote(); }, $shares));
237+
$superShare->setNote($allNotes);
238+
232239
// use most permissive permissions
233240
// this covers the case where there are multiple shares for the same
234241
// file e.g. from different groups and different permissions

0 commit comments

Comments
 (0)