Skip to content

Commit f308eef

Browse files
Merge pull request #62341 from nextcloud/perf/shareuser/display-name
perf(ShareUser): Only fetch display name instead of user object
2 parents d59f07a + ee1b854 commit f308eef

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

lib/public/Sharing/Recipient/ShareRecipient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public function format(ISharingRegistry $registry, IFactory $l10nFactory, IURLGe
5252
throw new RuntimeException('The recipient type is not registered: ' . $this->class);
5353
}
5454

55+
if ($this->instance !== null) {
56+
// TODO: Support federation
57+
throw new RuntimeException('Currently only local recipients are supported.');
58+
}
59+
5560
$displayName = $recipientType->getRecipientDisplayName($this->value) ?? $this->value;
5661
if (!$isUnique) {
5762
$displayName .= ' (' . $recipientType->getDisplayName($l10nFactory) . ': ' . $this->value . ')';

lib/public/Sharing/ShareUser.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,20 @@ public function isCurrentUser(ShareAccessContext $accessContext): bool {
4646
* @since 35.0.0
4747
*/
4848
public function format(IUserManager $userManager): array {
49-
$ownerUser = $userManager->get($this->userId);
50-
if ($ownerUser === null) {
51-
throw new RuntimeException('The userId does not exist: ' . $this->userId);
49+
if ($this->instance !== null) {
50+
// TODO: Support federation
51+
throw new RuntimeException('Currently only local users are supported.');
52+
}
53+
54+
$displayName = $userManager->getDisplayName($this->userId);
55+
if ($displayName === null) {
56+
throw new RuntimeException('No display name for user ' . $this->userId);
5257
}
5358

5459
return [
5560
'user_id' => $this->userId,
5661
'instance' => $this->instance,
57-
'display_name' => $ownerUser->getDisplayName(),
62+
'display_name' => $displayName,
5863
'icon' => (new ShareIconURL(
5964
$userManager->getAvatarUrlLight($this->userId, 64),
6065
$userManager->getAvatarUrlDark($this->userId, 64),

0 commit comments

Comments
 (0)