From db4ac24b86d5dce25665587baa770747c04176b2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 13 Feb 2026 16:32:22 +0100 Subject: [PATCH] feat: delay fetching the display name of a share recipient untill we need it Signed-off-by: Robin Appelman --- lib/private/Share20/DefaultShareProvider.php | 11 +++-------- lib/private/Share20/Share.php | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 17c6e9d572b1e..7085cebc44db6 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -1096,16 +1096,10 @@ private function createShare($data) { if ($share->getShareType() === IShare::TYPE_USER) { $share->setSharedWith($data['share_with']); - $displayName = $this->userManager->getDisplayName($data['share_with']); - if ($displayName !== null) { - $share->setSharedWithDisplayName($displayName); - } + $share->setSharedWithDisplayNameCallback(fn (IShare $share) => $this->userManager->getDisplayName($share->getSharedWith())); } elseif ($share->getShareType() === IShare::TYPE_GROUP) { $share->setSharedWith($data['share_with']); - $group = $this->groupManager->get($data['share_with']); - if ($group !== null) { - $share->setSharedWithDisplayName($group->getDisplayName()); - } + $share->setSharedWithDisplayNameCallback(fn (IShare $share) => $this->groupManager->getDisplayName($share->getSharedWith())); } elseif ($share->getShareType() === IShare::TYPE_LINK) { $share->setPassword($data['password']); $share->setSendPasswordByTalk((bool)$data['password_by_talk']); @@ -1462,6 +1456,7 @@ public function getAccessList($nodes, $currentAccess) { /** * For each user the path with the fewest slashes is returned + * * @param array $shares * @return array */ diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index 54223c57e2d1e..f1091160ea6d8 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -33,8 +33,9 @@ class Share implements IShare { private $shareType; /** @var string */ private $sharedWith; - /** @var string */ - private $sharedWithDisplayName; + private ?string $sharedWithDisplayName = null; + /** @var ?callable */ + private $sharedWithDisplayNameCallback = null; /** @var string */ private $sharedWithAvatar; /** @var string */ @@ -247,10 +248,20 @@ public function setSharedWithDisplayName($displayName) { } /** - * @inheritdoc + * @param callable(IShare):?string $callback + * @return $this */ + public function setSharedWithDisplayNameCallback(callable $callback) { + $this->sharedWithDisplayNameCallback = $callback; + return $this; + } + public function getSharedWithDisplayName() { - return $this->sharedWithDisplayName; + if ($this->sharedWithDisplayNameCallback !== null) { + $this->sharedWithDisplayName = ($this->sharedWithDisplayNameCallback)($this); + $this->sharedWithDisplayNameCallback = null; + } + return $this->sharedWithDisplayName ?? $this->sharedWith; } /**