summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib/Proxy.php
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2020-04-24 12:27:27 +0200
committerGitHub <noreply@github.com>2020-04-24 12:27:27 +0200
commit212138daa181cf1fbcb72b3129f8d3d5f94cf3b2 (patch)
tree37afc994d574ff437f2b90be3c909b36bc325bca /apps/user_ldap/lib/Proxy.php
parent84a35361599640d838815a4127eab58e49f052fc (diff)
parent4babdc082b988485608682a6a0bf3cccfd42fe8b (diff)
downloadnextcloud-server-212138daa181cf1fbcb72b3129f8d3d5f94cf3b2.tar.gz
nextcloud-server-212138daa181cf1fbcb72b3129f8d3d5f94cf3b2.zip
Merge pull request #19919 from nextcloud/enh/noid/ldpa_group_perf
LDAP Group Backend optimizations
Diffstat (limited to 'apps/user_ldap/lib/Proxy.php')
-rw-r--r--apps/user_ldap/lib/Proxy.php36
1 files changed, 25 insertions, 11 deletions
diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php
index 3cf55f8cd58..7bcbd19ff1c 100644
--- a/apps/user_ldap/lib/Proxy.php
+++ b/apps/user_ldap/lib/Proxy.php
@@ -40,6 +40,8 @@ use OCA\User_LDAP\User\Manager;
abstract class Proxy {
private static $accesses = [];
private $ldap = null;
+ /** @var bool */
+ private $isSingleBackend;
/** @var \OCP\ICache|null */
private $cache;
@@ -70,11 +72,11 @@ abstract class Proxy {
static $coreNotificationManager;
if ($fs === null) {
$ocConfig = \OC::$server->getConfig();
- $fs = new FilesystemHelper();
- $log = new LogWrapper();
- $avatarM = \OC::$server->getAvatarManager();
- $db = \OC::$server->getDatabaseConnection();
- $userMap = new UserMapping($db);
+ $fs = new FilesystemHelper();
+ $log = new LogWrapper();
+ $avatarM = \OC::$server->getAvatarManager();
+ $db = \OC::$server->getDatabaseConnection();
+ $userMap = new UserMapping($db);
$groupMap = new GroupMapping($db);
$coreUserManager = \OC::$server->getUserManager();
$coreNotificationManager = \OC::$server->getNotificationManager();
@@ -105,7 +107,7 @@ abstract class Proxy {
* @return string
*/
protected function getUserCacheKey($uid) {
- return 'user-'.$uid.'-lastSeenOn';
+ return 'user-' . $uid . '-lastSeenOn';
}
/**
@@ -113,7 +115,7 @@ abstract class Proxy {
* @return string
*/
protected function getGroupCacheKey($gid) {
- return 'group-'.$gid.'-lastSeenOn';
+ return 'group-' . $gid . '-lastSeenOn';
}
/**
@@ -139,8 +141,18 @@ abstract class Proxy {
*/
abstract public function getLDAPAccess($id);
+ abstract protected function activeBackends(): int;
+
+ protected function isSingleBackend(): bool {
+ if ($this->isSingleBackend === null) {
+ $this->isSingleBackend = $this->activeBackends() === 1;
+ }
+ return $this->isSingleBackend;
+ }
+
/**
* Takes care of the request to the User backend
+ *
* @param string $id
* @param string $method string, the method of the user backend that shall be called
* @param array $parameters an array of parameters to be passed
@@ -148,8 +160,10 @@ abstract class Proxy {
* @return mixed, the result of the specified method
*/
protected function handleRequest($id, $method, $parameters, $passOnWhen = false) {
- $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
- if ($result === $passOnWhen) {
+ if (!$this->isSingleBackend()) {
+ $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen);
+ }
+ if (!isset($result) || $result === $passOnWhen) {
$result = $this->walkBackends($id, $method, $parameters);
}
return $result;
@@ -164,7 +178,7 @@ abstract class Proxy {
if ($key === null) {
return $prefix;
}
- return $prefix.hash('sha256', $key);
+ return $prefix . hash('sha256', $key);
}
/**
@@ -193,7 +207,7 @@ abstract class Proxy {
if ($this->cache === null) {
return;
}
- $key = $this->getCacheKey($key);
+ $key = $this->getCacheKey($key);
$value = base64_encode(json_encode($value));
$this->cache->set($key, $value, 2592000);
}