feat: Build cache for character listings
This commit is contained in:
parent
0c73ba8263
commit
39fbc1b01d
|
@ -5,12 +5,15 @@
|
||||||
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
||||||
parameters:
|
parameters:
|
||||||
app.charlist.basepath: '%kernel.project_dir%/data/lists'
|
app.charlist.basepath: '%kernel.project_dir%/data/lists'
|
||||||
|
app.var.basepath: '%kernel.project_dir%/var'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# default configuration for services in *this* file
|
# default configuration for services in *this* file
|
||||||
_defaults:
|
_defaults:
|
||||||
autowire: true # Automatically injects dependencies in your services.
|
autowire: true # Automatically injects dependencies in your services.
|
||||||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
||||||
|
bind:
|
||||||
|
string $varBasepath: '%app.var.basepath%'
|
||||||
|
|
||||||
# makes classes in src/ available to be used as services
|
# makes classes in src/ available to be used as services
|
||||||
# this creates a service per class whose id is the fully-qualified class name
|
# this creates a service per class whose id is the fully-qualified class name
|
||||||
|
|
|
@ -9,6 +9,7 @@ use App\Utils\Number;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
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\VarExporter\VarExporter;
|
||||||
|
|
||||||
#[Route('/kanji', name: 'app_kanji_')]
|
#[Route('/kanji', name: 'app_kanji_')]
|
||||||
class KanjiController extends AbstractController
|
class KanjiController extends AbstractController
|
||||||
|
@ -16,6 +17,7 @@ class KanjiController extends AbstractController
|
||||||
function __construct(
|
function __construct(
|
||||||
private AnkiService $anki,
|
private AnkiService $anki,
|
||||||
private CharListService $charList,
|
private CharListService $charList,
|
||||||
|
private string $varBasepath,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public static function tmpl(string $path): string
|
public static function tmpl(string $path): string
|
||||||
|
@ -26,6 +28,10 @@ class KanjiController extends AbstractController
|
||||||
/** @return array<string, array<string, 0>> */
|
/** @return array<string, array<string, 0>> */
|
||||||
private function getCharInfo(): array
|
private function getCharInfo(): array
|
||||||
{
|
{
|
||||||
|
$cacheFile = "$this->varBasepath/charlist.php";
|
||||||
|
|
||||||
|
if (file_exists($cacheFile)) return require $cacheFile;
|
||||||
|
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
|
||||||
$lists = [
|
$lists = [
|
||||||
|
@ -59,6 +65,8 @@ class KanjiController extends AbstractController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_put_contents($cacheFile, '<?php return ' . VarExporter::export($ret) . ';');
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue