Skip to content

Commit

Permalink
préparation du cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi81 committed Jan 23, 2025
1 parent 4657f37 commit 989e8cb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 29 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@
"php bin/console lexik:jwt:generate-keypair",
"php bin/console lexik:jwt:check-config",
"rm docker-compose.yml",
"rm -rf .docker"
"rm -rf .docker",
"php bin/console at:cron:site:redis_cache_reset"
],
"php-config": [
"memory_limit=512M",
Expand Down
2 changes: 1 addition & 1 deletion cron.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"jobs": [
{
"command": "45 2 * * * php bin/console at:cron:site:cache_clear"
"command": "45 2 * * * php bin/console at:cron:site:redis_cache_reset"
},
{
"command": "0 3 * * * php bin/console at:cron:site:datas"
Expand Down
27 changes: 0 additions & 27 deletions src/Command/Cron/Site/ClearCacheCommand.php

This file was deleted.

69 changes: 69 additions & 0 deletions src/Command/Cron/Site/RedisCacheResetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Command\Cron\Site;

use App\Repository\Reference\ProjectReferenceRepository;
use App\Service\Aid\AidService;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'at:cron:site:redis_cache_reset', description: 'Vide le cache Redis')]
class RedisCacheResetCommand extends Command
{
public function __construct(
private CacheItemPoolInterface $cache,
private AidService $aidService,
private ProjectReferenceRepository $projectReferenceRepository
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->cache->clear();
$output->writeln('Cache vidé avec succès');

$aidParams = [
'showInSearch' => true,
];

$projectReferences = $this->projectReferenceRepository->findAll();

// on parcours les projets référents pour préparer le cache
foreach ($projectReferences as $projectReference) {
$this->aidService->searchAidsV3(
array_merge(
$aidParams,
[
'keyword' => $projectReference->getName(),
'orderBy' => [
'sort' => 'score_total',
'order' => 'DESC'
],
'projectReference' => $projectReference
],
)
);
$output->writeln('Cache '.$projectReference->getName().' préparé');
}

// préparation du cache sans filtres
$this->aidService->searchAidsV3(
array_merge(
$aidParams,
[
'orderBy' => [
'sort' => 'score_total',
'order' => 'DESC'
]
],
)
);
$output->writeln('Cache sans params préparé');

return Command::SUCCESS;
}
}

0 comments on commit 989e8cb

Please sign in to comment.