Performance: Cache translation catalogue to avoid reparsing YAML

This commit is contained in:
Toby Zerner 2017-11-11 22:45:38 +10:30
parent 5f7060fb4a
commit 9cc67fe312
3 changed files with 18 additions and 5 deletions

View File

@ -46,6 +46,7 @@
"nikic/fast-route": "^0.6",
"oyejorge/less.php": "~1.5",
"psr/http-message": "^1.0",
"symfony/config": "^2.7",
"symfony/console": "^2.7",
"symfony/http-foundation": "^2.7",
"symfony/translation": "^2.7",

View File

@ -14,35 +14,43 @@ namespace Flarum\Debug\Console;
use Flarum\Admin\WebApp as AdminWebApp;
use Flarum\Console\Command\AbstractCommand;
use Flarum\Forum\WebApp as ForumWebApp;
use Flarum\Foundation\Application;
use Illuminate\Contracts\Cache\Store;
class CacheClearCommand extends AbstractCommand
{
/**
* @var \Illuminate\Contracts\Cache\Store
* @var Store
*/
protected $cache;
/**
* @var \Flarum\Forum\WebApp
* @var ForumWebApp
*/
protected $forum;
/**
* @var \Flarum\Admin\WebApp
* @var AdminWebApp
*/
protected $admin;
/**
* @var Application
*/
protected $app;
/**
* @param Store $cache
* @param ForumWebApp $forum
* @param AdminWebApp $admin
* @param Application $app
*/
public function __construct(Store $cache, ForumWebApp $forum, AdminWebApp $admin)
public function __construct(Store $cache, ForumWebApp $forum, AdminWebApp $admin, Application $app)
{
$this->cache = $cache;
$this->forum = $forum;
$this->admin = $admin;
$this->app = $app;
parent::__construct();
}
@ -68,5 +76,9 @@ class CacheClearCommand extends AbstractCommand
$this->admin->getAssets()->flush();
$this->cache->flush();
$storagePath = $this->app->storagePath();
array_map('unlink', glob($storagePath.'/formatter/*'));
array_map('unlink', glob($storagePath.'/locale/*'));
}
}

View File

@ -41,7 +41,7 @@ class LocaleServiceProvider extends AbstractServiceProvider
$this->app->singleton('translator', function () {
$defaultLocale = $this->getDefaultLocale();
$translator = new Translator($defaultLocale, new MessageSelector());
$translator = new Translator($defaultLocale, null, $this->app->storagePath().'/locale', $this->app->inDebugMode());
$translator->setFallbackLocales([$defaultLocale, 'en']);
$translator->addLoader('prefixed_yaml', new PrefixedYamlFileLoader());