Skip to content

Commit

Permalink
Generating partial query only once
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Sep 9, 2019
1 parent f51198b commit a25a8f6
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/InnerResultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use TheCodingMachine\TDBM\QueryFactory\SmartEagerLoad\PartialQueryFactory;
use TheCodingMachine\TDBM\QueryFactory\SmartEagerLoad\Query\PartialQuery;
use TheCodingMachine\TDBM\QueryFactory\SmartEagerLoad\StorageNode;
use TheCodingMachine\TDBM\Utils\DbalUtils;

Expand Down Expand Up @@ -68,11 +69,13 @@ class InnerResultIterator implements \Iterator, \Countable, \ArrayAccess
*/
private $logger;
/**
* @var PartialQueryFactory|null
* @var PartialQuery|null
*/
private $partialQueryFactory;

protected $count = null;
private $partialQuery;
/**
* @var int|null
*/
protected $count;

private function __construct()
{
Expand All @@ -96,7 +99,11 @@ public static function createInnerResultIterator(string $magicSql, array $parame
$iterator->magicQuery = $magicQuery;
$iterator->databasePlatform = $iterator->tdbmService->getConnection()->getDatabasePlatform();
$iterator->logger = $logger;
$iterator->partialQueryFactory = $partialQueryFactory;
$partialQuery = null;
if ($iterator instanceof StorageNode && $partialQueryFactory !== null) {
$iterator->partialQuery = $partialQueryFactory->getPartialQuery($iterator, $magicQuery, $parameters);
}

return $iterator;
}

Expand Down Expand Up @@ -208,11 +215,6 @@ public function next()
$beansData[$columnDescriptor['tableGroup']][$columnDescriptor['table']][$columnDescriptor['column']] = $value;
}

$partialQuery = null;
if ($this instanceof StorageNode && $this->partialQueryFactory !== null) {
$partialQuery = $this->partialQueryFactory->getPartialQuery($this, $this->magicQuery, $this->parameters);
}

$reflectionClassCache = [];
$firstBean = true;
foreach ($beansData as $beanData) {
Expand Down Expand Up @@ -250,7 +252,7 @@ public function next()
// Let's bypass the constructor when creating the bean!
/** @var AbstractTDBMObject $bean */
$bean = $reflectionClassCache[$actualClassName]->newInstanceWithoutConstructor();
$bean->_constructFromData($beanData, $this->tdbmService, $partialQuery);
$bean->_constructFromData($beanData, $this->tdbmService, $this->partialQuery);
}

// The first bean is the one containing the main table.
Expand Down

0 comments on commit a25a8f6

Please sign in to comment.