diff options
author | blizzz <blizzz@owncloud.com> | 2014-04-16 10:36:19 +0200 |
---|---|---|
committer | blizzz <blizzz@owncloud.com> | 2014-04-16 10:36:19 +0200 |
commit | f6551d214fa4b947832ed83e94568fb4bfc0a410 (patch) | |
tree | e7a1afdc7fdbc59bb03bbe40c71461d5422cc194 /apps/user_ldap | |
parent | 23f2c48a43b2bc96370ec6b6411e6a86f705d12f (diff) | |
parent | ee3368d2ad8c362e27d904bbb22c7b741b09cff8 (diff) | |
download | nextcloud-server-f6551d214fa4b947832ed83e94568fb4bfc0a410.tar.gz nextcloud-server-f6551d214fa4b947832ed83e94568fb4bfc0a410.zip |
Merge pull request #7815 from owncloud/ldap_fix_usercount_master
correct LDAP user count on setup with many users (occ user:report)
Diffstat (limited to 'apps/user_ldap')
-rw-r--r-- | apps/user_ldap/lib/access.php | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index 4d187bab8d5..0b3ff4aa15e 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -659,7 +659,7 @@ class Access extends LDAPUtility { * @param string $filter */ public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) { - return $this->count($filter, $this->connection->ldapBaseGroups, $attr, $limit, $offset); + return $this->count($filter, $this->connection->ldapBaseUsers, $attr, $limit, $offset); } /** @@ -775,22 +775,47 @@ class Access extends LDAPUtility { */ 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); - $search = $this->executeSearch($filter, $base, $attr, $limit, $offset); - if($search === false) { - return false; + + if(is_null($limit)) { + $limit = $this->connection->ldapPagingSize; } - list($sr, $pagedSearchOK) = $search; - $cr = $this->connection->getConnectionResource(); + $counter = 0; - foreach($sr as $key => $res) { - $count = $this->ldap->countEntries($cr, $res); - if($count !== false) { - $counter += $count; + $count = null; + $cr = $this->connection->getConnectionResource(); + + do { + $continue = false; + $search = $this->executeSearch($filter, $base, $attr, + $limit, $offset); + if($search === false) { + return $counter > 0 ? $counter : false; } - } + list($sr, $pagedSearchOK) = $search; + + $count = $this->countEntriesInSearchResults($sr, $limit, $continue); + $counter += $count; - $this->processPagedSearchStatus($sr, $filter, $base, $counter, $limit, + $this->processPagedSearchStatus($sr, $filter, $base, $count, $limit, $offset, $pagedSearchOK, $skipHandling); + $offset += $limit; + } while($continue); + + return $counter; + } + + private function countEntriesInSearchResults($searchResults, $limit, + &$hasHitLimit) { + $cr = $this->connection->getConnectionResource(); + $count = 0; + + foreach($searchResults as $res) { + $count = intval($this->ldap->countEntries($cr, $res)); + $counter += $count; + if($count === $limit) { + $hasHitLimit = true; + } + } return $counter; } @@ -891,7 +916,7 @@ class Access extends LDAPUtility { //we slice the findings, when //a) paged search insuccessful, though attempted //b) no paged search, but limit set - if((!$this->pagedSearchedSuccessful + if((!$this->getPagedSearchResultState() && $pagedSearchOK) || ( !$pagedSearchOK @@ -1184,7 +1209,7 @@ class Access extends LDAPUtility { } $offset -= $limit; //we work with cache here - $cachekey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . $limit . '-' . $offset; + $cachekey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . intval($limit) . '-' . intval($offset); $cookie = ''; if(isset($this->cookies[$cachekey])) { $cookie = $this->cookies[$cachekey]; @@ -1206,7 +1231,7 @@ class Access extends LDAPUtility { */ private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { if(!empty($cookie)) { - $cachekey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .$limit . '-' . $offset; + $cachekey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset); $this->cookies[$cachekey] = $cookie; } } |