diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-02-02 04:55:11 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-02-02 04:55:11 +0300 |
commit | 478d539a61bc40a73a908aeed65efb0728360dfc (patch) | |
tree | fef4c98bedd98407a99addc5f0464a6618a3f172 /core/Common.php | |
parent | 90695622e41f4913ced772781f7d3dbbbb16af0f (diff) |
cache the returned value of those methods otherwise each of them triggers an event for each label in a datatable which can be many!
Diffstat (limited to 'core/Common.php')
-rw-r--r-- | core/Common.php | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/core/Common.php b/core/Common.php index dcadaa2d49..0fe9e34119 100644 --- a/core/Common.php +++ b/core/Common.php @@ -829,11 +829,20 @@ class Common */ public static function getSearchEngineUrls() { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php'; + $cacheId = 'Common.getSearchEngineUrls'; + $cache = Cache::getTransientCache(); + $searchEngines = $cache->fetch($cacheId); - $searchEngines = $GLOBALS['Piwik_SearchEngines']; + if (empty($searchEngines)) { - Piwik::postEvent('Referrer.addSearchEngineUrls', array(&$searchEngines)); + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php'; + + $searchEngines = $GLOBALS['Piwik_SearchEngines']; + + Piwik::postEvent('Referrer.addSearchEngineUrls', array(&$searchEngines)); + + $cache->save($cacheId, $searchEngines); + } return $searchEngines; } @@ -847,13 +856,21 @@ class Common */ public static function getSearchEngineNames() { - $searchEngines = self::getSearchEngineUrls(); + $cacheId = 'Common.getSearchEngineNames'; + $cache = Cache::getTransientCache(); + $nameToUrl = $cache->fetch($cacheId); + + if (empty($nameToUrl)) { + + $searchEngines = self::getSearchEngineUrls(); - $nameToUrl = array(); - foreach ($searchEngines as $url => $info) { - if (!isset($nameToUrl[$info[0]])) { - $nameToUrl[$info[0]] = $url; + $nameToUrl = array(); + foreach ($searchEngines as $url => $info) { + if (!isset($nameToUrl[$info[0]])) { + $nameToUrl[$info[0]] = $url; + } } + $cache->save($cacheId, $nameToUrl); } return $nameToUrl; @@ -868,11 +885,20 @@ class Common */ public static function getSocialUrls() { - require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php'; + $cacheId = 'Common.getSocialUrls'; + $cache = Cache::getTransientCache(); + $socialUrls = $cache->fetch($cacheId); + + if (empty($socialUrls)) { + + require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Socials.php'; - $socialUrls = $GLOBALS['Piwik_socialUrl']; + $socialUrls = $GLOBALS['Piwik_socialUrl']; - Piwik::postEvent('Referrer.addSocialUrls', array(&$socialUrls)); + Piwik::postEvent('Referrer.addSocialUrls', array(&$socialUrls)); + + $cache->save($cacheId, $socialUrls); + } return $socialUrls; } |