Merge pull request #1233 from SofHad/refactoring-duplicate-code
[Minor] Refactoring to avoid duplicate code
This commit is contained in:
commit
6448627bc9
@ -20,15 +20,14 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Cache\Persister;
|
namespace Doctrine\ORM\Cache\Persister;
|
||||||
|
|
||||||
use Doctrine\ORM\Cache\EntityCacheKey;
|
|
||||||
|
|
||||||
use Doctrine\Common\Util\ClassUtils;
|
use Doctrine\Common\Util\ClassUtils;
|
||||||
|
use Doctrine\ORM\Cache\EntityCacheKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific non-strict read/write cached entity persister
|
* Specific non-strict read/write cached entity persister
|
||||||
*
|
*
|
||||||
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
class NonStrictReadWriteCachedEntityPersister extends AbstractEntityPersister
|
class NonStrictReadWriteCachedEntityPersister extends AbstractEntityPersister
|
||||||
{
|
{
|
||||||
@ -41,41 +40,13 @@ class NonStrictReadWriteCachedEntityPersister extends AbstractEntityPersister
|
|||||||
|
|
||||||
if (isset($this->queuedCache['insert'])) {
|
if (isset($this->queuedCache['insert'])) {
|
||||||
foreach ($this->queuedCache['insert'] as $entity) {
|
foreach ($this->queuedCache['insert'] as $entity) {
|
||||||
$class = $this->class;
|
$isChanged = $this->updateCache($entity, $isChanged);
|
||||||
$className = ClassUtils::getClass($entity);
|
|
||||||
|
|
||||||
if ($className !== $this->class->name) {
|
|
||||||
$class = $this->metadataFactory->getMetadataFor($className);
|
|
||||||
}
|
|
||||||
|
|
||||||
$key = new EntityCacheKey($class->rootEntityName, $this->uow->getEntityIdentifier($entity));
|
|
||||||
$entry = $this->hydrator->buildCacheEntry($class, $key, $entity);
|
|
||||||
$cached = $this->region->put($key, $entry);
|
|
||||||
$isChanged = $isChanged ?: $cached;
|
|
||||||
|
|
||||||
if ($this->cacheLogger && $cached) {
|
|
||||||
$this->cacheLogger->entityCachePut($this->regionName, $key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->queuedCache['update'])) {
|
if (isset($this->queuedCache['update'])) {
|
||||||
foreach ($this->queuedCache['update'] as $entity) {
|
foreach ($this->queuedCache['update'] as $entity) {
|
||||||
$class = $this->class;
|
$isChanged = $this->updateCache($entity, $isChanged);
|
||||||
$className = ClassUtils::getClass($entity);
|
|
||||||
|
|
||||||
if ($className !== $this->class->name) {
|
|
||||||
$class = $this->metadataFactory->getMetadataFor($className);
|
|
||||||
}
|
|
||||||
|
|
||||||
$key = new EntityCacheKey($class->rootEntityName, $this->uow->getEntityIdentifier($entity));
|
|
||||||
$entry = $this->hydrator->buildCacheEntry($class, $key, $entity);
|
|
||||||
$cached = $this->region->put($key, $entry);
|
|
||||||
$isChanged = $isChanged ?: $cached;
|
|
||||||
|
|
||||||
if ($this->cacheLogger && $cached) {
|
|
||||||
$this->cacheLogger->entityCachePut($this->regionName, $key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,4 +92,19 @@ class NonStrictReadWriteCachedEntityPersister extends AbstractEntityPersister
|
|||||||
|
|
||||||
$this->queuedCache['update'][] = $entity;
|
$this->queuedCache['update'][] = $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateCache($entity, $isChanged)
|
||||||
|
{
|
||||||
|
$class = $this->metadataFactory->getMetadataFor(get_class($entity));
|
||||||
|
$key = new EntityCacheKey($class->rootEntityName, $this->uow->getEntityIdentifier($entity));
|
||||||
|
$entry = $this->hydrator->buildCacheEntry($class, $key, $entity);
|
||||||
|
$cached = $this->region->put($key, $entry);
|
||||||
|
$isChanged = $isChanged ?: $cached;
|
||||||
|
|
||||||
|
if ($this->cacheLogger && $cached) {
|
||||||
|
$this->cacheLogger->entityCachePut($this->regionName, $key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $isChanged;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user