diff options
author | Marc Hefter <marchefter@gmail.com> | 2023-04-14 11:08:46 +0200 |
---|---|---|
committer | Marc Hefter <marchefter@gmail.com> | 2023-04-14 11:08:46 +0200 |
commit | 64914593a0b3157a67621188a062e722b34976bd (patch) | |
tree | 27893a292c1dda28b3a0292a21244365e5f3bd08 /apps/user_ldap | |
parent | eec5e702da5ce7e6a65adb56ad611aee4c97f718 (diff) | |
download | nextcloud-server-64914593a0b3157a67621188a062e722b34976bd.tar.gz nextcloud-server-64914593a0b3157a67621188a062e722b34976bd.zip |
optimized handling of user profile data change
Check profile data checksum before updating user profile, to ensure
data has changed. Write checksum to user settings and cache.
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/User/User.php | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 8685ba0c60a..f6a3bf70792 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -237,9 +237,15 @@ class User { } unset($attr); + // check for cached profile data + $username = $this->getUsername(); // buffer variable, to save resource + $cacheKey = 'getUserProfile-'.$username; + $profileCached = $this->connection->getFromCache($cacheKey); // honoring profile disabled in config.php and check if user profile was refreshed if ($this->config->getSystemValueBool('profile.enabled', true) && + ($profileCached === null) && // no cache or TTL not expired !$this->wasRefreshed('profile')) { + // check current data $profileValues = array(); //User Profile Field - Phone number $attr = strtolower($this->connection->ldapAttributePhone); @@ -314,9 +320,25 @@ class User { = $ldapEntry[$attr][0]; } } + // check for changed data and cache just for TTL checking + $checksum = hash('sha256', json_encode($profileValues)); + $this->connection->writeToCache($cacheKey + , $checksum // write array to cache. is waste of cache space + , null); // use ldapCacheTTL from configuration // Update user profile - $this->updateProfile($profileValues); + if ($this->config->getUserValue($username, 'user_ldap', 'lastProfileChecksum', null) !== $checksum) { + $this->config->setUserValue($username, 'user_ldap', 'lastProfileChecksum', $checksum); + $this->updateProfile($profileValues); + $this->logger->info("updated profile uid=$username" + , ['app' => 'user_ldap']); + } else { + $this->logger->debug("profile data from LDAP unchanged" + , ['app' => 'user_ldap', 'uid' => $username]); + } unset($attr); + } elseif ($profileCached !== null) { // message delayed, to declutter log + $this->logger->debug("skipping profile check, while cached data exist" + , ['app' => 'user_ldap', 'uid' => $username]); } //Avatar |