diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-07-12 00:40:51 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-07-12 00:40:51 +0300 |
commit | ce9b7cb69e349489e74527749c47e080fed27128 (patch) | |
tree | 35e4a3266e4632c6961301eba0e2901ea5307f52 /plugins/CustomVariables | |
parent | 927c9379b7c717da88cca3fc158f4e814731c598 (diff) |
various performance tweaks (#14624)
* various performance tweaks
* tweak so tests dont fail
* Update Manager.php
* Update Plugin.php
* cache custom variables properly
Diffstat (limited to 'plugins/CustomVariables')
-rw-r--r-- | plugins/CustomVariables/CustomVariables.php | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php index 90ea2672ad..2437941f8a 100644 --- a/plugins/CustomVariables/CustomVariables.php +++ b/plugins/CustomVariables/CustomVariables.php @@ -24,7 +24,8 @@ class CustomVariables extends \Piwik\Plugin 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'Dimension.addDimensions' => 'addDimensions', - 'Actions.getCustomActionDimensionFieldsAndJoins' => 'provideActionDimensionFields' + 'Actions.getCustomActionDimensionFieldsAndJoins' => 'provideActionDimensionFields', + 'Tracker.setTrackerCacheGeneral' => 'getCacheGeneral' ); } @@ -78,32 +79,36 @@ class CustomVariables extends \Piwik\Plugin $cache = Cache::getCacheGeneral(); $cacheKey = self::MAX_NUM_CUSTOMVARS_CACHEKEY; - if (!array_key_exists($cacheKey, $cache)) { + return $cache[$cacheKey]; + } - $minCustomVar = null; + public function getCacheGeneral(&$cacheContent) + { + $cacheContent[self::MAX_NUM_CUSTOMVARS_CACHEKEY] = self::fetchNumMaxCustomVariables(); + } - foreach (Model::getScopes() as $scope) { - $model = new Model($scope); - $highestIndex = $model->getHighestCustomVarIndex(); + private static function fetchNumMaxCustomVariables() + { + $minCustomVar = null; - if (!isset($minCustomVar)) { - $minCustomVar = $highestIndex; - } + foreach (Model::getScopes() as $scope) { + $model = new Model($scope); + $highestIndex = $model->getHighestCustomVarIndex(); - if ($highestIndex < $minCustomVar) { - $minCustomVar = $highestIndex; - } + if (!isset($minCustomVar)) { + $minCustomVar = $highestIndex; } - if (!isset($minCustomVar)) { - $minCustomVar = 0; + if ($highestIndex < $minCustomVar) { + $minCustomVar = $highestIndex; } + } - $cache[$cacheKey] = $minCustomVar; - Cache::setCacheGeneral($cache); + if (!isset($minCustomVar)) { + $minCustomVar = 0; } - return $cache[$cacheKey]; + return $minCustomVar; } public function getClientSideTranslationKeys(&$translationKeys) |