From 6ca35561735811e57346b5cb1b1193d069804943 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 | 22 ++++++++++++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index cb91a44e602..1d446acd5e1 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -1118,16 +1118,10 @@ class DefaultShareProvider implements 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']); @@ -1488,6 +1482,7 @@ class DefaultShareProvider implements /** * 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 40a5054eed1..a89cbc458a3 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -35,8 +35,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 */ @@ -260,11 +261,24 @@ class Share implements IShare { } /** - * @inheritdoc + * @param callable(IShare):?string $callback + * @return $this */ + public function setSharedWithDisplayNameCallback(callable $callback) { + $this->sharedWithDisplayNameCallback = $callback; + return $this; + } + #[\Override] public function getSharedWithDisplayName() { - return $this->sharedWithDisplayName; + if ($this->sharedWithDisplayNameCallback !== null) { + $displayName = ($this->sharedWithDisplayNameCallback)($this); + if ($displayName !== null) { + $this->sharedWithDisplayName = $displayName; + } + $this->sharedWithDisplayNameCallback = null; + } + return $this->sharedWithDisplayName ?? ''; } /**