Optimization. Multiple get in QueryCache
This commit is contained in:
parent
247b085fce
commit
bb943afabe
@ -112,20 +112,29 @@ class DefaultQueryCache implements QueryCache
|
|||||||
$regionName = $region->getName();
|
$regionName = $region->getName();
|
||||||
|
|
||||||
$cm = $this->em->getClassMetadata($entityName);
|
$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
|
// @TODO - move to cache hydration component
|
||||||
foreach ($entry->result as $index => $entry) {
|
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) {
|
if ($this->cacheLogger !== null) {
|
||||||
$this->cacheLogger->entityCacheMiss($regionName, $entityKey);
|
$this->cacheLogger->entityCacheMiss($regionName, $entityCacheKeys[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->cacheLogger !== null) {
|
if ($this->cacheLogger !== null) {
|
||||||
$this->cacheLogger->entityCacheHit($regionName, $entityKey);
|
$this->cacheLogger->entityCacheHit($regionName, $entityCacheKeys[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $hasRelation) {
|
if ( ! $hasRelation) {
|
||||||
|
@ -294,8 +294,14 @@ class DefaultQueryCacheTest extends OrmTestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$this->region->addReturn('get', $entry);
|
$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');
|
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
|
||||||
|
|
||||||
@ -458,8 +464,14 @@ class DefaultQueryCacheTest extends OrmTestCase
|
|||||||
$entry->time = microtime(true) - 100;
|
$entry->time = microtime(true) - 100;
|
||||||
|
|
||||||
$this->region->addReturn('get', $entry);
|
$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');
|
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
|
||||||
|
|
||||||
@ -483,8 +495,14 @@ class DefaultQueryCacheTest extends OrmTestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
$this->region->addReturn('get', $entry);
|
$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');
|
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
|
||||||
|
|
||||||
@ -503,7 +521,7 @@ class DefaultQueryCacheTest extends OrmTestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->region->addReturn('get', $entry);
|
$this->region->addReturn('get', $entry);
|
||||||
$this->region->addReturn('get', null);
|
$this->region->addReturn('getMultiple', [null]);
|
||||||
|
|
||||||
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
|
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user