Skip to content

Commit

Permalink
Merge pull request #33563 from nextcloud/feat/make-displaynamecache-r…
Browse files Browse the repository at this point in the history
…eturn-null

Make DisplayNameCache return null if user doesn't exists
  • Loading branch information
CarlSchwan committed Aug 16, 2022
2 parents 604c175 + 8004aa7 commit 1c60ff5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function formatCacheEntry($entry, $path = null) {
private function getOwnerDisplayName() {
if (!$this->ownerDisplayName) {
$uid = $this->storage->getOwner('');
$this->ownerDisplayName = $this->displayNameCache->getDisplayName($uid);
$this->ownerDisplayName = $this->displayNameCache->getDisplayName($uid) ?? $uid;
}
return $this->ownerDisplayName;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/User/DisplayNameCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(ICacheFactory $cacheFactory, IUserManager $userManag
$this->userManager = $userManager;
}

public function getDisplayName(string $userId) {
public function getDisplayName(string $userId): ?string {
if (isset($this->cache[$userId])) {
return $this->cache[$userId];
}
Expand All @@ -61,7 +61,7 @@ public function getDisplayName(string $userId) {
if ($user) {
$displayName = $user->getDisplayName();
} else {
$displayName = $userId;
$displayName = null;
}
$this->cache[$userId] = $displayName;
$this->memCache->set($userId, $displayName, 60 * 10); // 10 minutes
Expand Down
2 changes: 1 addition & 1 deletion lib/private/User/LazyUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getUID() {
}

public function getDisplayName() {
return $this->userManager->getDisplayName($this->uid);
return $this->userManager->getDisplayName($this->uid) ?? $this->uid;
}

public function setDisplayName($displayName) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function get($uid) {
return null;
}

public function getDisplayName(string $uid): string {
public function getDisplayName(string $uid): ?string {
return $this->displayNameCache->getDisplayName($uid);
}

Expand Down
6 changes: 2 additions & 4 deletions lib/public/IUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ public function get($uid);
/**
* Get the display name of a user
*
* Note that this will return the uid if the user is not found instead of throwing an exception
*
* @param string $uid
* @return string
* @return string|null
* @since 25.0.0
*/
public function getDisplayName(string $uid): string;
public function getDisplayName(string $uid): ?string;

/**
* check if a user exists
Expand Down

0 comments on commit 1c60ff5

Please sign in to comment.