Skip to content

Commit 6f412a4

Browse files
committed
feat: delay fetching the display name of a share recipient untill we need it
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent b80816d commit 6f412a4

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

lib/private/Share20/DefaultShareProvider.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,16 +1096,10 @@ private function createShare($data) {
10961096

10971097
if ($share->getShareType() === IShare::TYPE_USER) {
10981098
$share->setSharedWith($data['share_with']);
1099-
$displayName = $this->userManager->getDisplayName($data['share_with']);
1100-
if ($displayName !== null) {
1101-
$share->setSharedWithDisplayName($displayName);
1102-
}
1099+
$share->setSharedWithDisplayNameCallback(fn (IShare $share) => $this->userManager->getDisplayName($share->getSharedWith()));
11031100
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
11041101
$share->setSharedWith($data['share_with']);
1105-
$group = $this->groupManager->get($data['share_with']);
1106-
if ($group !== null) {
1107-
$share->setSharedWithDisplayName($group->getDisplayName());
1108-
}
1102+
$share->setSharedWithDisplayNameCallback(fn (IShare $share) => $this->groupManager->getDisplayName($share->getSharedWith()));
11091103
} elseif ($share->getShareType() === IShare::TYPE_LINK) {
11101104
$share->setPassword($data['password']);
11111105
$share->setSendPasswordByTalk((bool)$data['password_by_talk']);
@@ -1462,6 +1456,7 @@ public function getAccessList($nodes, $currentAccess) {
14621456

14631457
/**
14641458
* For each user the path with the fewest slashes is returned
1459+
*
14651460
* @param array $shares
14661461
* @return array
14671462
*/

lib/private/Share20/Share.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ class Share implements IShare {
3333
private $shareType;
3434
/** @var string */
3535
private $sharedWith;
36-
/** @var string */
37-
private $sharedWithDisplayName;
36+
private ?string $sharedWithDisplayName;
37+
/** @var ?callable */
38+
private $sharedWithDisplayNameCallback;
3839
/** @var string */
3940
private $sharedWithAvatar;
4041
/** @var string */
@@ -247,9 +248,19 @@ public function setSharedWithDisplayName($displayName) {
247248
}
248249

249250
/**
250-
* @inheritdoc
251+
* @param callable(IShare):?string $callback
252+
* @return $this
251253
*/
254+
public function setSharedWithDisplayNameCallback(callable $callback) {
255+
$this->sharedWithDisplayNameCallback = $callback;
256+
return $this;
257+
}
258+
252259
public function getSharedWithDisplayName() {
260+
if ($this->sharedWithDisplayNameCallback !== null) {
261+
$this->sharedWithDisplayName = ($this->sharedWithDisplayNameCallback)($this);
262+
$this->sharedWithDisplayNameCallback = null;
263+
}
253264
return $this->sharedWithDisplayName;
254265
}
255266

0 commit comments

Comments
 (0)