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