Skip to content

Commit

Permalink
[doctrineGH-7633] Bugfix: Partial queries were stored in 2LC.
Browse files Browse the repository at this point in the history
There was a check in DefaultQueryCache that prevented partial queries,
because they are not supported. However the checked hint
Query::HINT_FORCE_PARTIAL_LOAD is optional, so cant be used to prevent
caching partial DQL queries.

Introduce a new hint that the SqlWalker sets on detecing a PARTIAL
query and throw an exception in the DefaultQueryCache if thats found.
  • Loading branch information
beberlei committed Mar 1, 2020
1 parent 9273057 commit 68c348d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Expand Up @@ -260,7 +260,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h
throw new CacheException("Second-level cache query supports only select statements.");
}

if (isset($hints[Query::HINT_FORCE_PARTIAL_LOAD]) && $hints[Query::HINT_FORCE_PARTIAL_LOAD]) {
if (isset($hints[Query\SqlWalker::HINT_PARTIAL]) && $hints[Query\SqlWalker::HINT_PARTIAL]) {
throw new CacheException("Second level cache does not support partial entities.");
}

Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/ORM/Query/SqlWalker.php
Expand Up @@ -46,6 +46,11 @@ class SqlWalker implements TreeWalker
*/
const HINT_DISTINCT = 'doctrine.distinct';

/**
* @var string
*/
const HINT_PARTIAL = 'doctrine.partial';

/**
* @var ResultSetMapping
*/
Expand Down Expand Up @@ -1366,6 +1371,8 @@ public function walkSelectExpression($selectExpression)
default:
// IdentificationVariable or PartialObjectExpression
if ($expr instanceof AST\PartialObjectExpression) {
$this->query->setHint(self::HINT_PARTIAL, true);

$dqlAlias = $expr->identificationVariable;
$partialFieldSet = $expr->partialFieldSet;
} else {
Expand Down
Expand Up @@ -1095,7 +1095,6 @@ public function testCacheablePartialQueryException()
$this->loadFixturesCountries();

$this->_em->createQuery("SELECT PARTIAL c.{id} FROM Doctrine\Tests\Models\Cache\Country c")
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
->setCacheable(true)
->getResult();
}
Expand Down

0 comments on commit 68c348d

Please sign in to comment.