summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvoxsim <Simon Vocella>2014-09-15 18:37:54 +0200
committervoxsim <Simon Vocella>2014-09-15 18:37:54 +0200
commit1366133d2bba33391b25a57ad0182b317fe3ecb6 (patch)
tree4264c6bad95599835580ff39b6bfa21ea899d2af
parenta49610e18a07d04dd3ed861e15b64a94b8a45e19 (diff)
downloadnextcloud-server-1366133d2bba33391b25a57ad0182b317fe3ecb6.tar.gz
nextcloud-server-1366133d2bba33391b25a57ad0182b317fe3ecb6.zip
add more logic in displayNamesInGroup for big user bases
-rw-r--r--lib/private/group/manager.php21
-rw-r--r--tests/lib/group/manager.php44
2 files changed, 49 insertions, 16 deletions
diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php
index 982a3ceec46..e3744ab7698 100644
--- a/lib/private/group/manager.php
+++ b/lib/private/group/manager.php
@@ -214,12 +214,23 @@ class Manager extends PublicEmitter {
if(!empty($search)) {
// only user backends have the capability to do a complex search for users
- $filteredUsers = $this->userManager->search($search);
- foreach($filteredUsers as $filteredUser) {
- if($group->inGroup($filteredUser)) {
- $groupUsers []= $filteredUser;
- }
+ $searchOffset = 0;
+ if($limit === -1) {
+ $searchLimit = $group->count('');
+ } else {
+ $searchLimit = $limit * 2;
}
+
+ do {
+ $filteredUsers = $this->userManager->search($search, $searchLimit, $searchOffset);
+ foreach($filteredUsers as $filteredUser) {
+ if($group->inGroup($filteredUser)) {
+ $groupUsers []= $filteredUser;
+ }
+ }
+ $searchOffset += $searchLimit;
+ } while(sizeof($groupUsers) < $searchLimit+$offset && sizeof($filteredUsers) > 0 && sizeof($filteredUsers) === $searchLimit);
+
if($limit === -1) {
$groupUsers = array_slice($groupUsers, $offset);
} else {
diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php
index d4a1a737837..70d9783946a 100644
--- a/tests/lib/group/manager.php
+++ b/tests/lib/group/manager.php
@@ -369,17 +369,31 @@ class Manager extends \PHPUnit_Framework_TestCase {
}
}));
+ $backend->expects($this->once())
+ ->method('implementsActions')
+ ->will($this->returnValue(true));
+
+ $backend->expects($this->once())
+ ->method('countUsersInGroup')
+ ->with('testgroup', '')
+ ->will($this->returnValue(2));
+
/**
* @var \OC\User\Manager $userManager
*/
$userManager = $this->getMock('\OC\User\Manager');
$userBackend = $this->getMock('\OC_User_Backend');
- $userManager->expects($this->once())
+ $userManager->expects($this->any())
->method('search')
->with('user3')
- ->will($this->returnValue(array('user3' => new User('user3', $userBackend),
- 'user33' => new User('user33', $userBackend))));
+ ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
+ switch($offset) {
+ case 0 : return array('user3' => new User('user3', $userBackend),
+ 'user33' => new User('user33', $userBackend));
+ case 2 : return array();
+ }
+ }));
$userManager->expects($this->any())
->method('get')
@@ -435,12 +449,16 @@ class Manager extends \PHPUnit_Framework_TestCase {
$userManager = $this->getMock('\OC\User\Manager');
$userBackend = $this->getMock('\OC_User_Backend');
- $userManager->expects($this->once())
+ $userManager->expects($this->any())
->method('search')
->with('user3')
- ->will($this->returnValue(array('user3' => new User('user3', $userBackend),
- 'user33' => new User('user33', $userBackend),
- 'user333' => new User('user333', $userBackend))));
+ ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
+ switch($offset) {
+ case 0 : return array('user3' => new User('user3', $userBackend),
+ 'user33' => new User('user33', $userBackend));
+ case 2 : return array('user333' => new User('user333', $userBackend));
+ }
+ }));
$userManager->expects($this->any())
->method('get')
@@ -498,12 +516,16 @@ class Manager extends \PHPUnit_Framework_TestCase {
$userManager = $this->getMock('\OC\User\Manager');
$userBackend = $this->getMock('\OC_User_Backend');
- $userManager->expects($this->once())
+ $userManager->expects($this->any())
->method('search')
->with('user3')
- ->will($this->returnValue(array('user3' => new User('user3', $userBackend),
- 'user33' => new User('user33', $userBackend),
- 'user333' => new User('user333', $userBackend))));
+ ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) {
+ switch($offset) {
+ case 0 : return array('user3' => new User('user3', $userBackend),
+ 'user33' => new User('user33', $userBackend));
+ case 2 : return array('user333' => new User('user333', $userBackend));
+ }
+ }));
$userManager->expects($this->any())
->method('get')