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