Skip to content

Commit

Permalink
Performance: Cache translation catalogue to avoid reparsing YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Nov 11, 2017
1 parent 5f7060f commit 9cc67fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -46,6 +46,7 @@
"nikic/fast-route": "^0.6",
"oyejorge/less.php": "~1.5",
"psr/http-message": "^1.0",
"symfony/config": "^2.7",

This comment has been minimized.

Copy link
@franzliedke

franzliedke Dec 13, 2017

Contributor

Why is this now needed?

This comment has been minimized.

Copy link
@tobyzerner

tobyzerner Dec 13, 2017

Author Contributor
"symfony/console": "^2.7",
"symfony/http-foundation": "^2.7",
"symfony/translation": "^2.7",
Expand Down
20 changes: 16 additions & 4 deletions src/Debug/Console/CacheClearCommand.php
Expand Up @@ -14,35 +14,43 @@
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();
}
Expand All @@ -68,5 +76,9 @@ protected function fire()
$this->admin->getAssets()->flush();

$this->cache->flush();

$storagePath = $this->app->storagePath();
array_map('unlink', glob($storagePath.'/formatter/*'));
array_map('unlink', glob($storagePath.'/locale/*'));
}
}
2 changes: 1 addition & 1 deletion src/Locale/LocaleServiceProvider.php
Expand Up @@ -41,7 +41,7 @@ public function register()
$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());

Expand Down

0 comments on commit 9cc67fe

Please sign in to comment.