Skip to content

Commit

Permalink
⚡ Avoid systematic count query
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenk committed May 14, 2024
1 parent b8f013a commit d8a2918
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
4 changes: 1 addition & 3 deletions src/PageIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ public static function createEmpyIterator(ResultIterator $parentResult): self
public function getIterator()
{
if ($this->innerResultIterator === null) {
if ($this->parentResult->count() === 0) {
$this->innerResultIterator = new EmptyInnerResultIterator();
} elseif ($this->mode === TDBMService::MODE_CURSOR) {
if ($this->mode === TDBMService::MODE_CURSOR) {
$this->innerResultIterator = InnerResultIterator::createInnerResultIterator($this->magicSql, $this->parameters, $this->limit, $this->offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->logger);
} else {
$this->innerResultIterator = InnerResultArray::createInnerResultIterator($this->magicSql, $this->parameters, $this->limit, $this->offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->logger);
Expand Down
17 changes: 0 additions & 17 deletions tests/AbstractTDBMObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,4 @@ public function testEmptyResultIterator()
$this->assertEquals(0, $d->count());
}

public function testEmptyPageIterator()
{
$a = ResultIterator::createEmpyIterator();
$b = $a->take(0, 10);
foreach ($b as $empty) {
throw new \LogicException("Not supposed to iterate on an empty page iterator.");
}
$this->assertEquals(0, $b->count());
$this->assertEquals([], $b->toArray());
$this->assertEquals(0, $b->totalCount());
$c = $b->map(function ($foo) {
});
foreach ($c as $empty) {
throw new \LogicException("Not supposed to iterate on an empty iterator.");
}
$this->assertEquals([], $c->toArray());
}
}

0 comments on commit d8a2918

Please sign in to comment.