From bdd37562f078cc077c34ab03919b8df00ee69a7a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sat, 3 Jun 2023 00:37:35 +0200 Subject: [PATCH] fix: do not fetch LDAP display name all the time - use cache and rely on background update mechanism - with ajax cron it will still run - core User must not cache uid as displayname to address edge case (early announcement with displayname not ready) Signed-off-by: Arthur Schiwon --- apps/user_ldap/lib/User_LDAP.php | 41 ++------------------------------ lib/private/User/User.php | 2 +- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index d787bfea4d40c..9c7c4bca93b5b 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -461,7 +461,7 @@ public function getHome($uid) { /** * get display name of the user * @param string $uid user ID of the user - * @return string|false display name + * @return ?string|false display name */ public function getDisplayName($uid) { if ($this->userPluginManager->implementsActions(Backend::GET_DISPLAYNAME)) { @@ -472,44 +472,7 @@ public function getDisplayName($uid) { return false; } - $cacheKey = 'getDisplayName'.$uid; - if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { - return $displayName; - } - - //Check whether the display name is configured to have a 2nd feature - $additionalAttribute = $this->access->connection->ldapUserDisplayName2; - $displayName2 = ''; - if ($additionalAttribute !== '') { - $displayName2 = $this->access->readAttribute( - $this->access->username2dn($uid), - $additionalAttribute); - } - - $displayName = $this->access->readAttribute( - $this->access->username2dn($uid), - $this->access->connection->ldapUserDisplayName); - - if ($displayName && (count($displayName) > 0)) { - $displayName = $displayName[0]; - - if (is_array($displayName2)) { - $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; - } - - $user = $this->access->userManager->get($uid); - if ($user instanceof User) { - $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); - $this->access->connection->writeToCache($cacheKey, $displayName); - } - if ($user instanceof OfflineUser) { - /** @var OfflineUser $user*/ - $displayName = $user->getDisplayName(); - } - return $displayName; - } - - return null; + return $this->ocConfig->getUserValue($uid, 'user_ldap', 'displayName', null); } /** diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 580c590e6eb54..a53d84794fd36 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -145,7 +145,7 @@ public function getDisplayName() { if (!empty($displayName)) { $this->displayName = $displayName; } else { - $this->displayName = $this->uid; + return $this->uid; } } return $this->displayName;