Skip to content

Commit

Permalink
Revert "handle more than limit users"
Browse files Browse the repository at this point in the history
This reverts commit 191fb29.
  • Loading branch information
butonic committed Nov 14, 2018
1 parent 0a2b0d8 commit e8564e2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 72 deletions.
23 changes: 2 additions & 21 deletions lib/private/User/Sync/AllUsersIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ class AllUsersIterator extends UsersIterator {
* @var UserInterface
*/
private $backend;
/**
* @var int the current data position,
* we need to track it independently of parent::$position to handle data sets larger thin LIMIT properly
*/
private $dataPos = 0;

/**
* @var int to cache the count($this->data) calculations
*/
private $endPos = 0;

public function __construct(UserInterface $backend) {
$this->backend = $backend;
Expand All @@ -45,23 +35,14 @@ public function __construct(UserInterface $backend) {
public function rewind() {
parent::rewind();
$this->data = $this->backend->getUsers('', self::LIMIT, 0);
$this->dataPos = 0;
$this->endPos = \count($this->data);
}

public function next() {
$this->position++;
$this->dataPos++;
if ($this->dataPos >= $this->endPos) {
$this->position++;
if ($this->currentDataPos() === 0) {
$this->page++;
$offset = $this->page * self::LIMIT;
$this->data = $this->backend->getUsers('', self::LIMIT, $offset);
$this->dataPos = 0;
$this->endPos = \count($this->data);
}
}

protected function currentDataPos() {
return $this->dataPos;
}
}
51 changes: 0 additions & 51 deletions tests/lib/User/Sync/AllUsersIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,55 +118,4 @@ public function testNext() {
$this->iterator->next();
$this->assertFalse($this->iterator->valid());
}

/**
* test a page larger than the internal limit / page size of 500
*/
public function testOverLimit() {

// create pages for 1201 users (0..1200)
$page1 = [];
for ($i=0; $i<600; $i++) {
$page1[] = "user$i";
}
$page2 = [];
for ($i=600; $i<1200; $i++) {
$page2[] = "user$i";
}
$page3 = ['user1200'];

$this->backend->expects($this->exactly(3))
->method('getUsers')
->withConsecutive(
[
$this->equalTo(''), // all users
$this->equalTo(UsersIterator::LIMIT), // limit 500
$this->equalTo(0) // at the beginning
], [
$this->equalTo(''), // all users
$this->equalTo(UsersIterator::LIMIT), // limit 500
$this->equalTo(500) // second page
], [
$this->equalTo(''), // all users
$this->equalTo(UsersIterator::LIMIT), // limit 500
$this->equalTo(1000) // last page
]
)
->willReturnOnConsecutiveCalls($page1, $page2, $page3);

// loop over iterator manually to check key() and valid()

$this->iterator->rewind();
$this->assertTrue($this->iterator->valid());
$this->assertEquals('user0', $this->iterator->current());
$this->assertEquals(0, $this->iterator->key());
for ($i=1; $i<=1200; $i++) {
$this->iterator->next();
$this->assertTrue($this->iterator->valid());
$this->assertEquals("user$i", $this->iterator->current());
$this->assertEquals($i, $this->iterator->key());
}
$this->iterator->next();
$this->assertFalse($this->iterator->valid());
}
}

0 comments on commit e8564e2

Please sign in to comment.