From d8a2918ed42c44cf9a109ae8b8b816db975deeb5 Mon Sep 17 00:00:00 2001 From: Kevin NGUYEN Date: Tue, 14 May 2024 16:20:52 +0200 Subject: [PATCH] :zap: Avoid systematic count query --- src/PageIterator.php | 4 +--- tests/AbstractTDBMObjectTest.php | 17 ----------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/src/PageIterator.php b/src/PageIterator.php index cd1da899..ab811179 100644 --- a/src/PageIterator.php +++ b/src/PageIterator.php @@ -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); diff --git a/tests/AbstractTDBMObjectTest.php b/tests/AbstractTDBMObjectTest.php index 3a79559d..1e60a610 100644 --- a/tests/AbstractTDBMObjectTest.php +++ b/tests/AbstractTDBMObjectTest.php @@ -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()); - } }