Merge pull request #58335 from nextcloud/lazy-share-recipient-displayname

feat: delay fetching the display name of a share recipient untill we need it
This commit is contained in:
Stephan Orbaugh 2026-06-09 16:23:56 +02:00 committed by GitHub
commit 0ea5449683
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 12 deletions

View file

@ -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
*/

View file

@ -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 ?? '';
}
/**