1
0
mirror of synced 2025-02-03 05:49:25 +03:00

Optimization. Multiple get in QueryCache

This commit is contained in:
Mikhail Polyanin 2016-05-20 13:42:13 +03:00 committed by Luís Cobucci
parent 247b085fce
commit bb943afabe
No known key found for this signature in database
GPG Key ID: 8042585A7DBC92E1
2 changed files with 37 additions and 10 deletions

View File

@ -112,20 +112,29 @@ class DefaultQueryCache implements QueryCache
$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));
// @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]);
}
return null;
}
if ($this->cacheLogger !== null) {
$this->cacheLogger->entityCacheHit($regionName, $entityKey);
$this->cacheLogger->entityCacheHit($regionName, $entityCacheKeys[$index]);
}
if ( ! $hasRelation) {

View File

@ -294,8 +294,14 @@ class DefaultQueryCacheTest extends OrmTestCase
];
$this->region->addReturn('get', $entry);
$this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[0]));
$this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[1]));
$this->region->addReturn(
'getMultiple',
[
new EntityCacheEntry(Country::class, $data[0]),
new EntityCacheEntry(Country::class, $data[1])
]
);
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
@ -458,8 +464,14 @@ class DefaultQueryCacheTest extends OrmTestCase
$entry->time = microtime(true) - 100;
$this->region->addReturn('get', $entry);
$this->region->addReturn('get', new EntityCacheEntry(Country::class, $entities[0]));
$this->region->addReturn('get', new EntityCacheEntry(Country::class, $entities[1]));
$this->region->addReturn(
'getMultiple',
[
new EntityCacheEntry(Country::class, $entities[0]),
new EntityCacheEntry(Country::class, $entities[1])
]
);
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
@ -483,8 +495,14 @@ class DefaultQueryCacheTest extends OrmTestCase
];
$this->region->addReturn('get', $entry);
$this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[0]));
$this->region->addReturn('get', new EntityCacheEntry(Country::class, $data[1]));
$this->region->addReturn(
'getMultiple',
[
new EntityCacheEntry(Country::class, $data[0]),
new EntityCacheEntry(Country::class, $data[1])
]
);
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
@ -503,7 +521,7 @@ class DefaultQueryCacheTest extends OrmTestCase
);
$this->region->addReturn('get', $entry);
$this->region->addReturn('get', null);
$this->region->addReturn('getMultiple', [null]);
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');