Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi get implementation in QueryCache #5831

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,29 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = ar
$regionName = $region->getName();

$cm = $this->em->getClassMetadata($entityName);

$entityCacheKeys = [];
foreach ($entry->result as $index => $concreteEntry) {
$entityCacheKeys[$index] = new EntityCacheKey($cm->rootEntityName, $concreteEntry['identifier']);
}
$entries = $region->getMultiple(new CollectionCacheEntry($entityCacheKeys));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius does it makes sense to extract this process to a named constructor on CollectionCacheEntry?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked...
In order to do that we would need make CollectionCacheEntry know about EntityCacheKey and now it just depends on CacheKey (abstract class), so it's better keep the dependency here.


// @TODO - move to cache hydration component
foreach ($entry->result as $index => $entry) {

if (($entityEntry = $region->get($entityKey = new EntityCacheKey($cm->rootEntityName, $entry['identifier']))) === null) {
$entityEntry = is_array($entries) && array_key_exists($index, $entries) ? $entries[$index] : null;

if ($entityEntry === null) {

if ($this->cacheLogger !== null) {
$this->cacheLogger->entityCacheMiss($regionName, $entityKey);
$this->cacheLogger->entityCacheMiss($regionName, $entityCacheKeys[$index]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also do something CollectionCacheEntry#get($index) here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just use CollectionCacheEntry#identifiers

}

return null;
}

if ($this->cacheLogger !== null) {
$this->cacheLogger->entityCacheHit($regionName, $entityKey);
$this->cacheLogger->entityCacheHit($regionName, $entityCacheKeys[$index]);
}

if ( ! $hasRelation) {
Expand Down
20 changes: 13 additions & 7 deletions tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ public function testGetBasicQueryResult()
);

$this->region->addReturn('get', $entry);
$this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[0]));
$this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[1]));
$this->region->addReturn('getMultiple', array(
new EntityCacheEntry(Country::CLASSNAME, $data[0]),
new EntityCacheEntry(Country::CLASSNAME, $data[1])
));

$rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c');

Expand Down Expand Up @@ -434,8 +436,10 @@ public function testGetShouldIgnoreOldQueryCacheEntryResult()
$entry->time = time() - 100;

$this->region->addReturn('get', $entry);
$this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[0]));
$this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $entities[1]));
$this->region->addReturn('getMultiple', array(
new EntityCacheEntry(Country::CLASSNAME, $entities[0]),
new EntityCacheEntry(Country::CLASSNAME, $entities[1])
));

$rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c');

Expand All @@ -457,8 +461,10 @@ public function testGetShouldIgnoreNonQueryCacheEntryResult()
);

$this->region->addReturn('get', $entry);
$this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[0]));
$this->region->addReturn('get', new EntityCacheEntry(Country::CLASSNAME, $data[1]));
$this->region->addReturn('getMultiple', array(
new EntityCacheEntry(Country::CLASSNAME, $data[0]),
new EntityCacheEntry(Country::CLASSNAME, $data[1])
));

$rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c');

Expand All @@ -475,7 +481,7 @@ public function testGetShouldIgnoreMissingEntityQueryCacheEntry()
));

$this->region->addReturn('get', $entry);
$this->region->addReturn('get', null);
$this->region->addReturn('getMultiple', [null]);

$rsm->addRootEntityFromClassMetadata(Country::CLASSNAME, 'c');

Expand Down