Skip to content

Commit

Permalink
doctrine#1277 DDC-3346 DDC-3531 - caching the currently in use persis…
Browse files Browse the repository at this point in the history
…ter context
  • Loading branch information
Ocramius committed Jan 22, 2015
1 parent 77dbba8 commit b5c7f2e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ class BasicEntityPersister implements EntityPersister
*/
protected $cachedPersisterContexts = [];

/**
* @var CachedPersisterContext
*/
protected $currentPersisterContext;

/**
* Initializes a new <tt>BasicEntityPersister</tt> that uses the given EntityManager
* and persists instances of the class described by the given ClassMetadata descriptor.
Expand All @@ -197,7 +202,11 @@ public function __construct(EntityManagerInterface $em, ClassMetadata $class)
$this->platform = $this->conn->getDatabasePlatform();
$this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
$this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory());
$this->cachedPersisterContexts['noLimits'] = new CachedPersisterContext(
$this->cachedPersisterContexts['noLimits'] = $this->currentPersisterContext = new CachedPersisterContext(
$class,
new Query\ResultSetMapping()
);
$this->cachedPersisterContexts['withLimits'] = new CachedPersisterContext(
$class,
new Query\ResultSetMapping()
);
Expand Down Expand Up @@ -1927,4 +1936,13 @@ protected function generateFilterConditionSQL(ClassMetadata $targetEntity, $targ
$sql = implode(' AND ', $filterClauses);
return $sql ? "(" . $sql . ")" : ""; // Wrap again to avoid "X or Y and FilterConditionSQL"
}

private function loadPersisterContext($offset, $limit)
{
if (null === $offset && null === $limit) {
$this->currentPersisterContext = $this->cachedPersisterContexts['noLimits'];
}

$this->currentPersisterContext = $this->cachedPersisterContexts['withLimits'];
}
}

0 comments on commit b5c7f2e

Please sign in to comment.