to reassure that selected attributes still work, do not count all matching entries but limit it to 1 in order to make it faster
This commit is contained in:
parent
71944a59a5
commit
f9b4f5f4e5
|
@ -887,8 +887,10 @@ class Access extends LDAPUtility implements user\IUserTools {
|
||||||
private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
|
private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
|
||||||
\OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG);
|
\OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG);
|
||||||
|
|
||||||
|
$limitPerPage = (intval($limit) < intval($this->connection->ldapPagingSize)) ?
|
||||||
|
intval($limit) : intval($this->connection->ldapPagingSize);
|
||||||
if(is_null($limit) || $limit <= 0) {
|
if(is_null($limit) || $limit <= 0) {
|
||||||
$limit = intval($this->connection->ldapPagingSize);
|
$limitPerPage = intval($this->connection->ldapPagingSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
|
@ -898,19 +900,19 @@ class Access extends LDAPUtility implements user\IUserTools {
|
||||||
do {
|
do {
|
||||||
$continue = false;
|
$continue = false;
|
||||||
$search = $this->executeSearch($filter, $base, $attr,
|
$search = $this->executeSearch($filter, $base, $attr,
|
||||||
$limit, $offset);
|
$limitPerPage, $offset);
|
||||||
if($search === false) {
|
if($search === false) {
|
||||||
return $counter > 0 ? $counter : false;
|
return $counter > 0 ? $counter : false;
|
||||||
}
|
}
|
||||||
list($sr, $pagedSearchOK) = $search;
|
list($sr, $pagedSearchOK) = $search;
|
||||||
|
|
||||||
$count = $this->countEntriesInSearchResults($sr, $limit, $continue);
|
$count = $this->countEntriesInSearchResults($sr, $limitPerPage, $continue);
|
||||||
$counter += $count;
|
$counter += $count;
|
||||||
|
|
||||||
$this->processPagedSearchStatus($sr, $filter, $base, $count, $limit,
|
$this->processPagedSearchStatus($sr, $filter, $base, $count, $limitPerPage,
|
||||||
$offset, $pagedSearchOK, $skipHandling);
|
$offset, $pagedSearchOK, $skipHandling);
|
||||||
$offset += $limit;
|
$offset += $limitPerPage;
|
||||||
} while($continue);
|
} while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
|
||||||
|
|
||||||
return $counter;
|
return $counter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,9 +132,10 @@ class Wizard extends LDAPUtility {
|
||||||
/**
|
/**
|
||||||
* counts users with a specified attribute
|
* counts users with a specified attribute
|
||||||
* @param string $attr
|
* @param string $attr
|
||||||
|
* @param bool $existsCheck
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
*/
|
*/
|
||||||
public function countUsersWithAttribute($attr) {
|
public function countUsersWithAttribute($attr, $existsCheck = false) {
|
||||||
if(!$this->checkRequirements(array('ldapHost',
|
if(!$this->checkRequirements(array('ldapHost',
|
||||||
'ldapPort',
|
'ldapPort',
|
||||||
'ldapBase',
|
'ldapBase',
|
||||||
|
@ -148,7 +149,9 @@ class Wizard extends LDAPUtility {
|
||||||
$attr . '=*'
|
$attr . '=*'
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->access->countUsers($filter);
|
$limit = ($existsCheck === false) ? null : 1;
|
||||||
|
|
||||||
|
return $this->access->countUsers($filter, array('dn'), $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,7 +172,7 @@ class Wizard extends LDAPUtility {
|
||||||
if($attr !== 'displayName' && !empty($attr)) {
|
if($attr !== 'displayName' && !empty($attr)) {
|
||||||
// most likely not the default value with upper case N,
|
// most likely not the default value with upper case N,
|
||||||
// verify it still produces a result
|
// verify it still produces a result
|
||||||
$count = intval($this->countUsersWithAttribute($attr));
|
$count = intval($this->countUsersWithAttribute($attr, true));
|
||||||
if($count > 0) {
|
if($count > 0) {
|
||||||
//no change, but we sent it back to make sure the user interface
|
//no change, but we sent it back to make sure the user interface
|
||||||
//is still correct, even if the ajax call was cancelled inbetween
|
//is still correct, even if the ajax call was cancelled inbetween
|
||||||
|
@ -181,7 +184,7 @@ class Wizard extends LDAPUtility {
|
||||||
// first attribute that has at least one result wins
|
// first attribute that has at least one result wins
|
||||||
$displayNameAttrs = array('displayname', 'cn');
|
$displayNameAttrs = array('displayname', 'cn');
|
||||||
foreach ($displayNameAttrs as $attr) {
|
foreach ($displayNameAttrs as $attr) {
|
||||||
$count = intval($this->countUsersWithAttribute($attr));
|
$count = intval($this->countUsersWithAttribute($attr, true));
|
||||||
|
|
||||||
if($count > 0) {
|
if($count > 0) {
|
||||||
$this->applyFind('ldap_display_name', $attr);
|
$this->applyFind('ldap_display_name', $attr);
|
||||||
|
@ -209,7 +212,7 @@ class Wizard extends LDAPUtility {
|
||||||
|
|
||||||
$attr = $this->configuration->ldapEmailAttribute;
|
$attr = $this->configuration->ldapEmailAttribute;
|
||||||
if(!empty($attr)) {
|
if(!empty($attr)) {
|
||||||
$count = intval($this->countUsersWithAttribute($attr));
|
$count = intval($this->countUsersWithAttribute($attr, true));
|
||||||
if($count > 0) {
|
if($count > 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue