]> source.dussan.org Git - nextcloud-server.git/commitdiff
cache group existence early to save useless requests to LDAP 18748/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Wed, 8 Jan 2020 10:02:37 +0000 (11:02 +0100)
committerBackportbot <backportbot-noreply@rullzer.com>
Wed, 8 Jan 2020 13:23:51 +0000 (13:23 +0000)
we do it for users already

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

index 62be63bc02b865b9a141234c4fe6f09fcb976fe8..64ee172a8bac1cbe02e8baff9391f5052ffbb6da 100644 (file)
@@ -345,7 +345,7 @@ class Access extends LDAPUtility {
                }
                return [];
        }
-       
+
        /**
         * Set password for an LDAP user identified by a DN
         *
@@ -646,6 +646,8 @@ class Access extends LDAPUtility {
                        if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
                                $this->cacheUserExists($name);
                                $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
+                       } elseif (!$isUser) {
+                               $this->cacheGroupExists($name);
                        }
                        return true;
                }
@@ -749,6 +751,13 @@ class Access extends LDAPUtility {
                $this->connection->writeToCache('userExists'.$ocName, true);
        }
 
+       /**
+        * caches a group as existing
+        */
+       public function cacheGroupExists(string $gid): void {
+               $this->connection->writeToCache('groupExists'.$gid, true);
+       }
+
        /**
         * caches the user display name
         * @param string $ocName the internal Nextcloud username
@@ -938,7 +947,15 @@ class Access extends LDAPUtility {
         * @return array
         */
        public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) {
-               return $this->fetchList($this->searchGroups($filter, $attr, $limit, $offset), $this->manyAttributes($attr));
+               $groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);
+               array_walk($groupRecords, function($record) {
+                       $newlyMapped = false;
+                       $gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
+                       if(!$newlyMapped && is_string($gid)) {
+                               $this->cacheGroupExists($gid);
+                       }
+               });
+               return $this->fetchList($groupRecords, $this->manyAttributes($attr));
        }
 
        /**
index c7b8528df626997fae622d46c8f4d1ba4548e97c..924466e6004bac45703b6e3bbca6398adb50f0ff 100644 (file)
@@ -1146,7 +1146,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
                                                $uuid,
                                                false
                                        );
-                                       $this->access->connection->writeToCache("groupExists" . $gid, true);
+                                       $this->access->cacheGroupExists($gid);
                                }
                        }
                        return $dn != null;