feat: Allow character list force-rebuild with "no-cache"

This commit is contained in:
Dendy 2025-09-03 08:30:53 +02:00
parent 39fbc1b01d
commit 46ae2a17b2
1 changed files with 5 additions and 3 deletions

View File

@ -7,6 +7,7 @@ use App\Service\AnkiService;
use App\Service\CharListService;
use App\Utils\Number;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\VarExporter\VarExporter;
@ -26,11 +27,11 @@ class KanjiController extends AbstractController
}
/** @return array<string, array<string, 0>> */
private function getCharInfo(): array
private function getCharInfo(bool $force = false): array
{
$cacheFile = "$this->varBasepath/charlist.php";
if (file_exists($cacheFile)) return require $cacheFile;
if (!$force and file_exists($cacheFile)) return require $cacheFile;
$ret = [];
@ -74,12 +75,13 @@ class KanjiController extends AbstractController
public function index(
string $start,
string $end,
Request $request,
): Response {
$jiten = json_decode(file_get_contents(
"{$this->getParameter('kernel.project_dir')}/data/kanken-links.json",
), true);
$charInfo = $this->getCharInfo();
$charInfo = $this->getCharInfo(force: $request->isNoCache());
$chars = [];
foreach (range(intval("{$start}0", 16), intval("{$end}f", 16)) as $codepoint) {