Browse Source

Make DisplayNameCache return null if user doesn't exists

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
tags/v25.0.0beta2
Carl Schwan 1 year ago
parent
commit
8004aa7721
No account linked to committer's email address

+ 1
- 1
apps/files_sharing/lib/Cache.php 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;
}

+ 2
- 2
lib/private/User/DisplayNameCache.php 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

+ 1
- 1
lib/private/User/LazyUser.php 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) {

+ 1
- 1
lib/private/User/Manager.php 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);
}


+ 2
- 4
lib/public/IUserManager.php 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

Loading…
Cancel
Save