Skip to content

Commit d8a2918

Browse files
committed
⚡ Avoid systematic count query
1 parent b8f013a commit d8a2918

File tree

2 files changed

+1
-20
lines changed

2 files changed

+1
-20
lines changed

src/PageIterator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ public static function createEmpyIterator(ResultIterator $parentResult): self
121121
public function getIterator()
122122
{
123123
if ($this->innerResultIterator === null) {
124-
if ($this->parentResult->count() === 0) {
125-
$this->innerResultIterator = new EmptyInnerResultIterator();
126-
} elseif ($this->mode === TDBMService::MODE_CURSOR) {
124+
if ($this->mode === TDBMService::MODE_CURSOR) {
127125
$this->innerResultIterator = InnerResultIterator::createInnerResultIterator($this->magicSql, $this->parameters, $this->limit, $this->offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->logger);
128126
} else {
129127
$this->innerResultIterator = InnerResultArray::createInnerResultIterator($this->magicSql, $this->parameters, $this->limit, $this->offset, $this->columnDescriptors, $this->objectStorage, $this->className, $this->tdbmService, $this->magicQuery, $this->logger);

tests/AbstractTDBMObjectTest.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,4 @@ public function testEmptyResultIterator()
4242
$this->assertEquals(0, $d->count());
4343
}
4444

45-
public function testEmptyPageIterator()
46-
{
47-
$a = ResultIterator::createEmpyIterator();
48-
$b = $a->take(0, 10);
49-
foreach ($b as $empty) {
50-
throw new \LogicException("Not supposed to iterate on an empty page iterator.");
51-
}
52-
$this->assertEquals(0, $b->count());
53-
$this->assertEquals([], $b->toArray());
54-
$this->assertEquals(0, $b->totalCount());
55-
$c = $b->map(function ($foo) {
56-
});
57-
foreach ($c as $empty) {
58-
throw new \LogicException("Not supposed to iterate on an empty iterator.");
59-
}
60-
$this->assertEquals([], $c->toArray());
61-
}
6245
}

0 commit comments

Comments
 (0)