Optimize admin performance / caching

This commit is contained in:
Matias Griese
2014-10-07 12:12:21 +03:00
parent 41821c57ab
commit 33a7df85e3
5 changed files with 21 additions and 13 deletions

View File

@@ -91,9 +91,6 @@ class AdminPlugin extends Plugin
// Only activate admin if we're inside the admin path. // Only activate admin if we're inside the admin path.
if (substr($this->uri->route(), 0, strlen($this->base)) == $this->base) { if (substr($this->uri->route(), 0, strlen($this->base)) == $this->base) {
// Disable system caching.
$this->config->set('system.cache.enabled', false);
// Change login behavior. // Change login behavior.
$this->config->set('plugins.login', $this->config->get('plugins.admin.login')); $this->config->set('plugins.login', $this->config->get('plugins.admin.login'));
@@ -239,10 +236,6 @@ class AdminPlugin extends Plugin
'onTwigSiteVariables' => ['onTwigSiteVariables', 1000] 'onTwigSiteVariables' => ['onTwigSiteVariables', 1000]
]); ]);
// Disable system caching.
$this->config->set('system.cache.enabled', false);
// Change login behavior. // Change login behavior.
$this->config->set('plugins.login', $this->config->get('plugins.admin.login')); $this->config->set('plugins.login', $this->config->get('plugins.admin.login'));

View File

@@ -1,6 +1,7 @@
<?php <?php
namespace Grav\Plugin; namespace Grav\Plugin;
use Grav\Common\File\CompiledYamlFile;
use Grav\Common\User\User; use Grav\Common\User\User;
use Grav\Common\Grav; use Grav\Common\Grav;
use Grav\Common\Plugins; use Grav\Common\Plugins;
@@ -12,7 +13,7 @@ use Grav\Common\Data;
use Grav\Common\GPM\Local\Packages as LocalPackages; use Grav\Common\GPM\Local\Packages as LocalPackages;
use RocketTheme\Toolbox\File\File; use RocketTheme\Toolbox\File\File;
use RocketTheme\Toolbox\File\LogFile; use RocketTheme\Toolbox\File\LogFile;
use RocketTheme\Toolbox\File\YamlFile; use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use RocketTheme\Toolbox\Session\Message; use RocketTheme\Toolbox\Session\Message;
use RocketTheme\Toolbox\Session\Session; use RocketTheme\Toolbox\Session\Session;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
@@ -135,7 +136,7 @@ class Admin
public function authenticate($form) public function authenticate($form)
{ {
if (!$this->user->authenticated && isset($form['username']) && isset($form['password'])) { if (!$this->user->authenticated && isset($form['username']) && isset($form['password'])) {
$file = YamlFile::instance(ACCOUNTS_DIR . $form['username'] . YAML_EXT); $file = CompiledYamlFile::instance(ACCOUNTS_DIR . $form['username'] . YAML_EXT);
if ($file->exists()) { if ($file->exists()) {
$user = new User($file->content()); $user = new User($file->content());
$user->authenticated = true; $user->authenticated = true;
@@ -226,7 +227,7 @@ class Admin
$config = $this->grav['config']; $config = $this->grav['config'];
$obj = new Data\Data($config->get('system'), $blueprints); $obj = new Data\Data($config->get('system'), $blueprints);
$obj->merge($post); $obj->merge($post);
$file = YamlFile::instance(USER_DIR . "config/{$type}.yaml"); $file = CompiledYamlFile::instance(USER_DIR . "config/{$type}.yaml");
$obj->file($file); $obj->file($file);
$data[$type] = $obj; $data[$type] = $obj;
break; break;
@@ -238,7 +239,7 @@ class Admin
$config = $this->grav['config']; $config = $this->grav['config'];
$obj = new Data\Data($config->get('site'), $blueprints); $obj = new Data\Data($config->get('site'), $blueprints);
$obj->merge($post); $obj->merge($post);
$file = YamlFile::instance(USER_DIR . "config/{$type}.yaml"); $file = CompiledYamlFile::instance(USER_DIR . "config/{$type}.yaml");
$obj->file($file); $obj->file($file);
$data[$type] = $obj; $data[$type] = $obj;
break; break;
@@ -248,11 +249,17 @@ class Admin
break; break;
default: default:
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$filename = $locator->findResource("config://{$type}.yaml", true, true);
$file = CompiledYamlFile::instance($filename);
if (preg_match('|plugins/|', $type)) { if (preg_match('|plugins/|', $type)) {
/** @var Plugins $plugins */ /** @var Plugins $plugins */
$plugins = $this->grav['plugins']; $plugins = $this->grav['plugins'];
$obj = $plugins->get(preg_replace('|plugins/|', '', $type)); $obj = $plugins->get(preg_replace('|plugins/|', '', $type));
$obj->merge($post); $obj->merge($post);
$obj->file($file);
$data[$type] = $obj; $data[$type] = $obj;
} elseif (preg_match('|themes/|', $type)) { } elseif (preg_match('|themes/|', $type)) {
@@ -260,6 +267,7 @@ class Admin
$themes = $this->grav['themes']; $themes = $this->grav['themes'];
$obj = $themes->get(preg_replace('|themes/|', '', $type)); $obj = $themes->get(preg_replace('|themes/|', '', $type));
$obj->merge($post); $obj->merge($post);
$obj->file($file);
$data[$type] = $obj; $data[$type] = $obj;
} else { } else {

View File

@@ -305,6 +305,13 @@ class AdminController
$this->admin->setMessage('Successfully saved'); $this->admin->setMessage('Successfully saved');
} }
if ($this->view != 'pages') {
// Force configuration reload.
/** @var Config $config */
$config = $this->grav['config'];
$config->reload();
}
// Redirect to new location. // Redirect to new location.
if ($obj instanceof Page\Page && $obj->route() != $this->admin->route()) { if ($obj instanceof Page\Page && $obj->route() != $this->admin->route()) {
$this->setRedirect($this->view . '/' . $obj->route()); $this->setRedirect($this->view . '/' . $obj->route());

View File

@@ -13,7 +13,7 @@
<h1><i class="fa fa-fw fa-plug"></i> Plugins</h1> <h1><i class="fa fa-fw fa-plug"></i> Plugins</h1>
{% else %} {% else %}
<div class="button-bar"> <div class="button-bar">
<button class="button" type="submit" name="task" value="add"><i class="fa fa-check"></i> Save</button> <button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> Save</button>
</div> </div>
<h1><i class="fa fa-fw fa-plug"></i> Plugin: {{ plugin.name|e }}</h1> <h1><i class="fa fa-fw fa-plug"></i> Plugin: {{ plugin.name|e }}</h1>
{% endif %} {% endif %}

View File

@@ -13,7 +13,7 @@
<h1><i class="fa fa-fw fa-plug"></i> Themes</h1> <h1><i class="fa fa-fw fa-plug"></i> Themes</h1>
{% else %} {% else %}
<div class="button-bar"> <div class="button-bar">
<button class="button" type="submit" name="task" value="add"><i class="fa fa-check"></i> Save</button> <button class="button" type="submit" name="task" value="save" form="blueprints"><i class="fa fa-check"></i> Save</button>
</div> </div>
<h1><i class="fa fa-fw fa-plug"></i> Theme: {{ theme.name|e }}</h1> <h1><i class="fa fa-fw fa-plug"></i> Theme: {{ theme.name|e }}</h1>
{% endif %} {% endif %}