Merge pull request #33563 from nextcloud/feat/make-displaynamecache-return-null

Make DisplayNameCache return null if user doesn't exists
This commit is contained in:
Carl Schwan 2022-08-16 18:36:45 +02:00 committed by GitHub
commit 1c60ff5936
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 9 deletions

View file

@ -170,7 +170,7 @@ class Cache extends CacheJail {
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;
}

View file

@ -47,7 +47,7 @@ class DisplayNameCache implements IEventListener {
$this->userManager = $userManager;
}
public function getDisplayName(string $userId) {
public function getDisplayName(string $userId): ?string {
if (isset($this->cache[$userId])) {
return $this->cache[$userId];
}
@ -61,7 +61,7 @@ class DisplayNameCache implements IEventListener {
if ($user) {
$displayName = $user->getDisplayName();
} else {
$displayName = $userId;
$displayName = null;
}
$this->cache[$userId] = $displayName;
$this->memCache->set($userId, $displayName, 60 * 10); // 10 minutes

View file

@ -51,7 +51,7 @@ class LazyUser implements IUser {
}
public function getDisplayName() {
return $this->userManager->getDisplayName($this->uid);
return $this->userManager->getDisplayName($this->uid) ?? $this->uid;
}
public function setDisplayName($displayName) {

View file

@ -188,7 +188,7 @@ class Manager extends PublicEmitter implements IUserManager {
return null;
}
public function getDisplayName(string $uid): string {
public function getDisplayName(string $uid): ?string {
return $this->displayNameCache->getDisplayName($uid);
}

View file

@ -87,13 +87,11 @@ interface IUserManager {
/**
* 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