mirror of
https://github.com/nextcloud/server.git
synced 2026-03-31 06:36:18 -04:00
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:
commit
1c60ff5936
5 changed files with 7 additions and 9 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue