summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2012-09-21 13:03:28 +0200
committerArthur Schiwon <blizzz@owncloud.com>2012-09-21 13:03:28 +0200
commit2a7a928ae9e808652029d3d8febe9d4d8b05558c (patch)
treeb237c022bc6d627bd3d9dfb0b28c840cb4360684
parent8f2c76d3da40d4f0957a5d073bddda742228b48f (diff)
downloadnextcloud-server-2a7a928ae9e808652029d3d8febe9d4d8b05558c.tar.gz
nextcloud-server-2a7a928ae9e808652029d3d8febe9d4d8b05558c.zip
LDAP: replace expensive recursiveArraySearch with direct SQL search, leading to a performance boost. Imorives UX especially on directories with tons of users, solves complains on ML and probably fixes oc.1080
-rw-r--r--apps/user_ldap/lib/access.php57
1 files changed, 38 insertions, 19 deletions
diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php
index 53619ab4c1d..d855ae2a163 100644
--- a/apps/user_ldap/lib/access.php
+++ b/apps/user_ldap/lib/access.php
@@ -206,21 +206,17 @@ abstract class Access {
$dn = $this->sanitizeDN($dn);
$table = $this->getMapTable($isUser);
if($isUser) {
+ $fncFindMappedName = 'findMappedUser';
$nameAttribute = $this->connection->ldapUserDisplayName;
} else {
+ $fncFindMappedName = 'findMappedGroup';
$nameAttribute = $this->connection->ldapGroupDisplayName;
}
- $query = \OCP\DB::prepare('
- SELECT `owncloud_name`
- FROM `'.$table.'`
- WHERE `ldap_dn` = ?
- ');
-
//let's try to retrieve the ownCloud name from the mappings table
- $component = $query->execute(array($dn))->fetchOne();
- if($component) {
- return $component;
+ $ocname = $this->$fncFindMappedName($dn);
+ if($ocname) {
+ return $ocname;
}
//second try: get the UUID and check if it is known. Then, update the DN and return the name.
@@ -295,25 +291,48 @@ abstract class Access {
return $this->ldap2ownCloudNames($ldapGroups, false);
}
+ private function findMappedUser($dn) {
+ static $query = null;
+ if(is_null($query)) {
+ $query = \OCP\DB::prepare('
+ SELECT `owncloud_name`
+ FROM `'.$this->getMapTable(true).'`
+ WHERE `ldap_dn` = ?'
+ );
+ }
+ $res = $query->execute(array($dn))->fetchOne();
+ if($res) {
+ return $res;
+ }
+ return false;
+ }
+
+ private function findMappedGroup($dn) {
+ static $query = null;
+ if(is_null($query)) {
+ $query = \OCP\DB::prepare('
+ SELECT `owncloud_name`
+ FROM `'.$this->getMapTable(false).'`
+ WHERE `ldap_dn` = ?'
+ );
+ }
+ $res = $query->execute(array($dn))->fetchOne();
+ if($res) {
+ return $res;
+ }
+ return false;
+ }
+
+
private function ldap2ownCloudNames($ldapObjects, $isUsers) {
if($isUsers) {
- $knownObjects = $this->mappedUsers();
$nameAttribute = $this->connection->ldapUserDisplayName;
} else {
- $knownObjects = $this->mappedGroups();
$nameAttribute = $this->connection->ldapGroupDisplayName;
}
$ownCloudNames = array();
foreach($ldapObjects as $ldapObject) {
- $key = \OCP\Util::recursiveArraySearch($knownObjects, $ldapObject['dn']);
-
- //everything is fine when we know the group
- if($key !== false) {
- $ownCloudNames[] = $knownObjects[$key]['owncloud_name'];
- continue;
- }
-
$ocname = $this->dn2ocname($ldapObject['dn'], $ldapObject[$nameAttribute], $isUsers);
if($ocname) {
$ownCloudNames[] = $ocname;