Skip to content
Extraits de code Groupes Projets
Valider 97941db8 rédigé par Matthieu Aubry's avatar Matthieu Aubry Validation de GitHub
Parcourir les fichiers

Restore the speed of Visitor Log (#12009)

* render template only if needed

* reuse same Twig instance

* cache CacheBuster to prevent recalculation when needed multiple times
parent 5d90f2e0
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -27,20 +27,32 @@ class UIAssetCacheBuster extends Singleton ...@@ -27,20 +27,32 @@ class UIAssetCacheBuster extends Singleton
*/ */
public function piwikVersionBasedCacheBuster($pluginNames = false) public function piwikVersionBasedCacheBuster($pluginNames = false)
{ {
$masterFile = PIWIK_INCLUDE_PATH . '/.git/refs/heads/master'; static $cachedCacheBuster = null;
$currentGitHash = file_exists($masterFile) ? @file_get_contents($masterFile) : null;
$pluginNames = !$pluginNames ? Manager::getInstance()->getLoadedPluginsName() : $pluginNames; if (empty($cachedCacheBuster) || $pluginNames !== false) {
sort($pluginNames);
$pluginsInfo = ''; $masterFile = PIWIK_INCLUDE_PATH . '/.git/refs/heads/master';
foreach ($pluginNames as $pluginName) { $currentGitHash = file_exists($masterFile) ? @file_get_contents($masterFile) : null;
$plugin = Manager::getInstance()->getLoadedPlugin($pluginName);
$pluginsInfo .= $plugin->getPluginName() . $plugin->getVersion() . ','; $plugins = !$pluginNames ? Manager::getInstance()->getLoadedPluginsName() : $pluginNames;
sort($plugins);
$pluginsInfo = '';
foreach ($plugins as $pluginName) {
$plugin = Manager::getInstance()->getLoadedPlugin($pluginName);
$pluginsInfo .= $plugin->getPluginName() . $plugin->getVersion() . ',';
}
$cacheBuster = md5($pluginsInfo . PHP_VERSION . Version::VERSION . trim($currentGitHash));
if ($pluginNames !== false) {
return $cacheBuster;
}
$cachedCacheBuster = $cacheBuster;
} }
$cacheBuster = md5($pluginsInfo . PHP_VERSION . Version::VERSION . trim($currentGitHash)); return $cachedCacheBuster;
return $cacheBuster;
} }
/** /**
......
...@@ -212,10 +212,15 @@ class View implements ViewInterface ...@@ -212,10 +212,15 @@ class View implements ViewInterface
return isset($this->templateVars[$name]); return isset($this->templateVars[$name]);
} }
/** @var Twig */
static $twigCached = null;
private function initializeTwig() private function initializeTwig()
{ {
$piwikTwig = new Twig(); if (empty(static::$twigCached)) {
$this->twig = $piwikTwig->getTwigEnvironment(); static::$twigCached = new Twig();
}
$this->twig = static::$twigCached->getTwigEnvironment();
} }
/** /**
......
...@@ -68,6 +68,10 @@ class VisitorDetails extends VisitorDetailsAbstract ...@@ -68,6 +68,10 @@ class VisitorDetails extends VisitorDetailsAbstract
public function renderVisitorDetails($visitInfo) public function renderVisitorDetails($visitInfo)
{ {
if (empty($visitInfo['customVariables'])) {
return [];
}
$view = new View('@CustomVariables/_visitorDetails'); $view = new View('@CustomVariables/_visitorDetails');
$view->visitInfo = $visitInfo; $view->visitInfo = $visitInfo;
return [[ 50, $view->render() ]]; return [[ 50, $view->render() ]];
......
{% if visitInfo.getColumn('customVariables') %} <div class="visitorCustomVariables">
<div class="visitorCustomVariables">
{% for id,customVariable in visitInfo.getColumn('customVariables') %} {% for id,customVariable in visitInfo.getColumn('customVariables') %}
{% set name='customVariableName' ~ id %} {% set name='customVariableName' ~ id %}
{% set value='customVariableValue' ~ id %} {% set value='customVariableValue' ~ id %}
...@@ -9,5 +8,4 @@ ...@@ -9,5 +8,4 @@
</abbr> </abbr>
{% if customVariable[value]|length > 0 %}: {{ customVariable[value]|truncate(50) }}{% endif %} {% if customVariable[value]|length > 0 %}: {{ customVariable[value]|truncate(50) }}{% endif %}
{% endfor %} {% endfor %}
</div> </div>
{% endif %} \ No newline at end of file
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter