SPRA-26 add redit- to test

This commit is contained in:
2024-08-02 16:07:05 +02:00
parent 9b549fa9e7
commit 2c8e32deb8
13 changed files with 55 additions and 6 deletions
+4
View File
@@ -10,6 +10,10 @@ framework:
# Redis
app: cache.adapter.redis
system: cache.adapter.redis
default_redis_provider: '%env(REDIS_URL)%'
pools:
database.cache:
adapter: cache.adapter.redis
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
#app: cache.adapter.apcu
+18
View File
@@ -15,6 +15,24 @@ doctrine:
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
second_level_cache:
enabled: true
regions:
user_cache:
lifetime: 8640000
cache_driver: { type: service, id: database.cache }
schedule_cache:
lifetime: 864000
cache_driver: { type: service, id: database.cache }
report_cache:
lifetime: 864000
cache_driver: { type: service, id: database.cache }
client_cache:
lifetime: 864000
cache_driver: { type: service, id: database.cache }
default_cache:
lifetime: 864000
cache_driver: { type: service, id: database.cache }
mappings:
App:
type: attribute
+16 -4
View File
@@ -23,6 +23,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\Cache\CacheInterface;
class BaseController extends AbstractController
{
@@ -42,14 +43,14 @@ class BaseController extends AbstractController
}
#[Route('/reports/{monthId}', name: 'app_base')]
#[IsGranted('reportView')]
public function reportsIndex(EntityManagerInterface $entityManager, int $monthId = 0) : Response
public function reportsIndex(EntityManagerInterface $entityManager, CacheInterface $cache, int $monthId = 0) : Response
{
$isOverdue = false;
$monthCurrent = $this->monthHelper->getCurrentMonth($monthId);
$reportsAll = $this->takeReportsAll($entityManager,$cache,$monthCurrent);
if ($monthId > -1) {
$monthCurrent = $this->monthHelper->getCurrentMonth($monthId);
$reportsAll = $entityManager->getRepository(Reports::class)->findAllInMonth($monthCurrent);
} else {
$reportsAll = $entityManager->getRepository(Reports::class)->findAllOverdue();
$isOverdue = true;
}
@@ -73,4 +74,15 @@ class BaseController extends AbstractController
'isOverdue' => $isOverdue,
]);
}
private function takeReportsAll(EntityManagerInterface $entityManager, CacheInterface $cache, ?\DateTime $monthCurrent = null) : array
{
if ($monthCurrent !== null) {
$ret = $entityManager->getRepository(Reports::class)->findAllInMonth($monthCurrent);
} else {
$ret = $entityManager->getRepository(Reports::class)->findAllOverdue();
}
return $ret;
}
}
@@ -76,6 +76,7 @@ class ClientController extends AbstractController
$newClient = $form->getData();
$entityManager->persist($newClient);
$entityManager->flush();
$entityManager->getCache()->evictEntityRegion(Clients::class);
if (!$isEdit) {
$addReports->setClient($newClient);
$addReports->init();
@@ -48,6 +48,7 @@ class ReportsController extends AbstractController
$report->setDone($isDone);
$entityManager->persist($report);
$entityManager->flush();
$entityManager->getCache()->evictCollection(Reports::class,"reportsTodos",$report->getId());
$reportsService->tryAddNextReport();
}
return $this->redirect($request->headers->get('referer'));
+1
View File
@@ -9,6 +9,7 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ClientsRepository::class)]
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'client_cache')]
class Clients
{
#[ORM\Id]
+1
View File
@@ -7,6 +7,7 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: NotesRepository::class)]
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'default_cache')]
class Notes
{
#[ORM\Id]
+3
View File
@@ -11,6 +11,8 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ReportsRepository::class)]
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'report_cache')]
class Reports
{
#[ORM\Id]
@@ -29,6 +31,7 @@ class Reports
* @var Collection<int, ReportsTodo>
*/
#[ORM\OneToMany(targetEntity: ReportsTodo::class, mappedBy: 'report', orphanRemoval: true)]
#[ORM\Cache(usage: 'READ_ONLY', region: 'report_cache')]
private Collection $reportsTodos;
+2 -1
View File
@@ -9,6 +9,7 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ReportsTodoRepository::class)]
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'report_cache')]
class ReportsTodo
{
#[ORM\Id]
@@ -19,7 +20,7 @@ class ReportsTodo
#[ORM\Column(type: Types::SMALLINT, enumType: ReportTodoEnum::class)]
private ?ReportTodoEnum $name = null;
#[ORM\ManyToOne]
#[ORM\ManyToOne(inversedBy: 'reportsTodos')]
#[ORM\JoinColumn(referencedColumnName: 'id', nullable: false)]
private ?Reports $report = null;
+1
View File
@@ -8,6 +8,7 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ScheduleRepository::class)]
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'schedule_cache')]
class Schedule
{
#[ORM\Id]
+1
View File
@@ -11,6 +11,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USERNAME', fields: ['username'])]
#[ORM\Cache(usage: 'READ_ONLY', region: 'user_cache')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
+4 -1
View File
@@ -17,8 +17,11 @@ class MonthHelper
}
public function getCurrentMonth(int $monthId) : \DateTime
public function getCurrentMonth(int $monthId) : ?\DateTime
{
if ($monthId < 0) {
return null;
}
$months = $this->takeMonths();
if ($monthId==0) {
$currentMonth = intval(date("n"));
+2
View File
@@ -84,6 +84,7 @@ class AddReports
$report->setNumber($numberOfReports + 1);
$this->manager->persist($report);
$this->manager->flush();
$this->manager->getCache()->evictEntityRegion(Reports::class);
}
return true;
}
@@ -107,6 +108,7 @@ class AddReports
$report->setDateStart($dateToReport->modify("+".self::NEXT_REPORT_MONTH." months"));
$this->manager->persist($report);
$this->manager->flush();
$this->manager->getCache()->evictEntityRegion(Reports::class);
return true;
}
}