diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-24 01:11:15 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-06-24 01:11:15 +0400 |
commit | bc31046e9c068b587cc0f3210126b345c8e3f8c6 (patch) | |
tree | 1148f41790865283ec6fe8dbabba55fe284cc191 /core/Metrics.php | |
parent | a83037ce24271c387a72f5ea2c8dec0527bf3dd4 (diff) |
added new staticCache to remove a lot of duplicated code and to have a nice interface, by caching the default metrics we reduce the calls to translate from 50k to 2k resulting in good performance improvement...
Diffstat (limited to 'core/Metrics.php')
-rw-r--r-- | core/Metrics.php | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/core/Metrics.php b/core/Metrics.php index 1eee0caf24..459708b152 100644 --- a/core/Metrics.php +++ b/core/Metrics.php @@ -9,6 +9,8 @@ namespace Piwik; +use Piwik\Cache\PluginAwareStaticCache; + require_once PIWIK_INCLUDE_PATH . "/core/Piwik.php"; /** @@ -219,6 +221,12 @@ class Metrics static public function getDefaultMetricTranslations() { + $cache = new PluginAwareStaticCache('DefaultMetricTranslations'); + + if ($cache->has()) { + return $cache->get(); + } + $translations = array( 'label' => 'General_ColumnLabel', 'date' => 'General_Date', @@ -264,6 +272,8 @@ class Metrics $translations = array_map(array('\\Piwik\\Piwik','translate'), $translations); + $cache->set($translations); + return $translations; } @@ -323,6 +333,12 @@ class Metrics static public function getDefaultMetricsDocumentation() { + $cache = new PluginAwareStaticCache('DefaultMetricsDocumentation'); + + if ($cache->has()) { + return $cache->get(); + } + $translations = array( 'nb_visits' => 'General_ColumnNbVisitsDocumentation', 'nb_uniq_visitors' => 'General_ColumnNbUniqVisitorsDocumentation', @@ -343,7 +359,11 @@ class Metrics */ Piwik::postEvent('Metrics.getDefaultMetricDocumentationTranslations', array(&$translations)); - return array_map(array('\\Piwik\\Piwik','translate'), $translations); + $translations = array_map(array('\\Piwik\\Piwik','translate'), $translations); + + $cache->set($translations); + + return $translations; } public static function getPercentVisitColumn() |