mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-09 19:13:26 +00:00
Add cache key prefix in cached collection repository
This commit is contained in:
@@ -48,11 +48,11 @@ class DbalCollectionRepositoryFactory implements CollectionRepositoryFactory
|
||||
*/
|
||||
public function createRepositoryForDatabox($databoxId)
|
||||
{
|
||||
$connection = $this->databoxConnectionProvider->getConnection($databoxId);
|
||||
$databoxConnection = $this->databoxConnectionProvider->getConnection($databoxId);
|
||||
|
||||
return new DbalCollectionRepository(
|
||||
$databoxId,
|
||||
$connection,
|
||||
$databoxConnection,
|
||||
$this->collectionReferenceRepository,
|
||||
$this->collectionFactory
|
||||
);
|
||||
|
@@ -56,7 +56,7 @@ final class CachedCollectionRepository implements CollectionRepository
|
||||
*/
|
||||
public function findAll()
|
||||
{
|
||||
$cacheKey = hash('sha256', $this->cacheKey);
|
||||
$cacheKey = $this->getCacheKey();
|
||||
/** @var \collection[] $collections */
|
||||
$collections = $this->cache->fetch($cacheKey);
|
||||
|
||||
@@ -91,7 +91,7 @@ final class CachedCollectionRepository implements CollectionRepository
|
||||
{
|
||||
$this->repository->save($collection);
|
||||
|
||||
$cacheKey = hash('sha256', $this->cacheKey);
|
||||
$cacheKey = $this->getCacheKey();
|
||||
|
||||
$this->cache->delete($cacheKey);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ final class CachedCollectionRepository implements CollectionRepository
|
||||
{
|
||||
$this->repository->delete($collection);
|
||||
|
||||
$cacheKey = hash('sha256', $this->cacheKey);
|
||||
$cacheKey = $this->getCacheKey();
|
||||
|
||||
$this->cache->delete($cacheKey);
|
||||
}
|
||||
@@ -109,4 +109,14 @@ final class CachedCollectionRepository implements CollectionRepository
|
||||
{
|
||||
$this->cache->save($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getCacheKey()
|
||||
{
|
||||
$cacheKey = 'collections:' . hash('sha256', $this->cacheKey);
|
||||
|
||||
return $cacheKey;
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ class DbalCollectionRepository implements CollectionRepository
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
private $databoxConnection;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
@@ -44,18 +44,18 @@ class DbalCollectionRepository implements CollectionRepository
|
||||
|
||||
/**
|
||||
* @param $databoxId
|
||||
* @param Connection $connection
|
||||
* @param Connection $databoxConnection
|
||||
* @param CollectionReferenceRepository $referenceRepository
|
||||
* @param CollectionFactory $collectionFactory
|
||||
*/
|
||||
public function __construct(
|
||||
$databoxId,
|
||||
Connection $connection,
|
||||
Connection $databoxConnection,
|
||||
CollectionReferenceRepository $referenceRepository,
|
||||
CollectionFactory $collectionFactory
|
||||
) {
|
||||
$this->databoxId = (int) $databoxId;
|
||||
$this->connection = $connection;
|
||||
$this->databoxConnection = $databoxConnection;
|
||||
$this->referenceRepository = $referenceRepository;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class DbalCollectionRepository implements CollectionRepository
|
||||
$parameters = [ 'collectionIds' => $parameters ];
|
||||
$parameterTypes = [ 'collectionIds' => Connection::PARAM_INT_ARRAY ];
|
||||
|
||||
$rows = $this->connection->fetchAll($query, $parameters, $parameterTypes);
|
||||
$rows = $this->databoxConnection->fetchAll($query, $parameters, $parameterTypes);
|
||||
|
||||
return $this->collectionFactory->createMany($this->databoxId, $references, $rows);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class DbalCollectionRepository implements CollectionRepository
|
||||
}
|
||||
|
||||
$query = self::$selectQuery . ' WHERE coll_id = :collectionId';
|
||||
$row = $this->connection->fetchAssoc($query, [ ':collectionId' => $reference->getCollectionId() ]);
|
||||
$row = $this->databoxConnection->fetchAssoc($query, [ ':collectionId' => $reference->getCollectionId() ]);
|
||||
|
||||
if ($row !== false) {
|
||||
return $this->collectionFactory->create($this->databoxId, $reference, $row);
|
||||
@@ -122,7 +122,7 @@ class DbalCollectionRepository implements CollectionRepository
|
||||
}
|
||||
|
||||
$query = self::$selectQuery . ' WHERE coll_id = :collectionId';
|
||||
$row = $this->connection->fetchAssoc($query, [ ':collectionId' => $reference->getCollectionId() ]);
|
||||
$row = $this->databoxConnection->fetchAssoc($query, [ ':collectionId' => $reference->getCollectionId() ]);
|
||||
|
||||
if ($row !== false) {
|
||||
return $this->collectionFactory->create($this->databoxId, $reference, $row);
|
||||
@@ -154,10 +154,10 @@ class DbalCollectionRepository implements CollectionRepository
|
||||
$isInsert = false;
|
||||
}
|
||||
|
||||
$this->connection->executeQuery($query, $parameters);
|
||||
$this->databoxConnection->executeQuery($query, $parameters);
|
||||
|
||||
if ($isInsert) {
|
||||
$collection->setCollectionId($this->connection->lastInsertId());
|
||||
$collection->setCollectionId($this->databoxConnection->lastInsertId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,6 +167,6 @@ class DbalCollectionRepository implements CollectionRepository
|
||||
'collectionId' => $collection->getCollectionId()
|
||||
];
|
||||
|
||||
$this->connection->executeQuery(self::$deleteQuery, $parameters);
|
||||
$this->databoxConnection->executeQuery(self::$deleteQuery, $parameters);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user