Skip to content

Commit 5c496c4

Browse files
nguyenkhomersimpsons
authored andcommitted
⚡ Avoid systematic count query (#285)
* ⚡ Avoid systematic count query * fix CI * Fix PHPStan * fix CI again
1 parent 9304078 commit 5c496c4

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/EmptyResultIterator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace TheCodingMachine\TDBM;
4+
5+
class EmptyResultIterator extends ResultIterator
6+
{
7+
}

src/PageIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static function createEmpyIterator(ResultIterator $parentResult): self
121121
public function getIterator(): \Traversable
122122
{
123123
if ($this->innerResultIterator === null) {
124-
if ($this->parentResult->count() === 0) {
124+
if ($this->parentResult instanceof EmptyResultIterator) {
125125
$this->innerResultIterator = new EmptyInnerResultIterator();
126126
} elseif ($this->mode === TDBMService::MODE_CURSOR) {
127127
$this->innerResultIterator = InnerResultIterator::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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testEmptyResultIterator()
4444

4545
public function testEmptyPageIterator()
4646
{
47-
$a = ResultIterator::createEmpyIterator();
47+
$a = EmptyResultIterator::createEmpyIterator();
4848
$b = $a->take(0, 10);
4949
foreach ($b as $empty) {
5050
throw new \LogicException("Not supposed to iterate on an empty page iterator.");

0 commit comments

Comments
 (0)