Skip to content

Commit 1c60ff5

Browse files
authored
Merge pull request #33563 from nextcloud/feat/make-displaynamecache-return-null
Make DisplayNameCache return null if user doesn't exists
2 parents 604c175 + 8004aa7 commit 1c60ff5

5 files changed

Lines changed: 7 additions & 9 deletions

File tree

apps/files_sharing/lib/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected function formatCacheEntry($entry, $path = null) {
170170
private function getOwnerDisplayName() {
171171
if (!$this->ownerDisplayName) {
172172
$uid = $this->storage->getOwner('');
173-
$this->ownerDisplayName = $this->displayNameCache->getDisplayName($uid);
173+
$this->ownerDisplayName = $this->displayNameCache->getDisplayName($uid) ?? $uid;
174174
}
175175
return $this->ownerDisplayName;
176176
}

lib/private/User/DisplayNameCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(ICacheFactory $cacheFactory, IUserManager $userManag
4747
$this->userManager = $userManager;
4848
}
4949

50-
public function getDisplayName(string $userId) {
50+
public function getDisplayName(string $userId): ?string {
5151
if (isset($this->cache[$userId])) {
5252
return $this->cache[$userId];
5353
}
@@ -61,7 +61,7 @@ public function getDisplayName(string $userId) {
6161
if ($user) {
6262
$displayName = $user->getDisplayName();
6363
} else {
64-
$displayName = $userId;
64+
$displayName = null;
6565
}
6666
$this->cache[$userId] = $displayName;
6767
$this->memCache->set($userId, $displayName, 60 * 10); // 10 minutes

lib/private/User/LazyUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getUID() {
5151
}
5252

5353
public function getDisplayName() {
54-
return $this->userManager->getDisplayName($this->uid);
54+
return $this->userManager->getDisplayName($this->uid) ?? $this->uid;
5555
}
5656

5757
public function setDisplayName($displayName) {

lib/private/User/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function get($uid) {
188188
return null;
189189
}
190190

191-
public function getDisplayName(string $uid): string {
191+
public function getDisplayName(string $uid): ?string {
192192
return $this->displayNameCache->getDisplayName($uid);
193193
}
194194

lib/public/IUserManager.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ public function get($uid);
8787
/**
8888
* Get the display name of a user
8989
*
90-
* Note that this will return the uid if the user is not found instead of throwing an exception
91-
*
9290
* @param string $uid
93-
* @return string
91+
* @return string|null
9492
* @since 25.0.0
9593
*/
96-
public function getDisplayName(string $uid): string;
94+
public function getDisplayName(string $uid): ?string;
9795

9896
/**
9997
* check if a user exists

0 commit comments

Comments
 (0)