]> source.dussan.org Git - nextcloud-server.git/commitdiff
don't circulate with only one backend
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Thu, 12 Mar 2020 11:45:52 +0000 (12:45 +0100)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Fri, 17 Apr 2020 10:38:52 +0000 (12:38 +0200)
- saves some overhead costs
- in some occasions saves LDAP requests

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/user_ldap/lib/Group_Proxy.php
apps/user_ldap/lib/Proxy.php
apps/user_ldap/lib/User_Proxy.php

index 3bd0cc4c4005ae1ee766000eb1c98fd0a8054eb2..a586906df8e0fcda08e188c82a81d4e27591becc 100644 (file)
@@ -60,7 +60,9 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
                $cacheKey = $this->getGroupCacheKey($gid);
                foreach ($this->backends as $configPrefix => $backend) {
                        if ($result = call_user_func_array([$backend, $method], $parameters)) {
-                               $this->writeToCache($cacheKey, $configPrefix);
+                               if(!$this->isSingleBackend()) {
+                                       $this->writeToCache($cacheKey, $configPrefix);
+                               }
                                return $result;
                        }
                }
@@ -99,6 +101,10 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
                return false;
        }
 
+       protected function activeBackends(): int {
+               return count($this->backends);
+       }
+
        /**
         * is user in group?
         * @param string $uid uid of the user
index 3cf55f8cd58674a1d4efeaad8d561760a0a319c0..09f4ac407d8d1df9855443e57aac6e9f3554e734 100644 (file)
@@ -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;
@@ -139,6 +141,15 @@ 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
@@ -148,8 +159,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;
index e9ff92d03eb2e32f8495c5d0718e08f3d941a436..d4eba412b4051ba9797369302d7d4c1718d3b78c 100644 (file)
@@ -86,7 +86,9 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
                                $instance = $this->getAccess($configPrefix);
                        }
                        if ($result = call_user_func_array([$instance, $method], $parameters)) {
-                               $this->writeToCache($cacheKey, $configPrefix);
+                               if(!$this->isSingleBackend()) {
+                                       $this->writeToCache($cacheKey, $configPrefix);
+                               }
                                return $result;
                        }
                }
@@ -130,6 +132,10 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
                return false;
        }
 
+       protected function activeBackends(): int {
+               return count($this->backends);
+       }
+
        /**
         * Check if backend implements actions
         * @param int $actions bitwise-or'ed actions