Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Aubry <matt@piwik.org>2014-12-17 06:40:11 +0300
committerMatthieu Aubry <matt@piwik.org>2014-12-17 06:40:11 +0300
commit0ca1479b57d2320468ff70fb3f1e7b7cb4177518 (patch)
treeeb481bfec3da927599bbc3801fc37b51b0badb43
parent579911e258528cfcea5c5fbaa78e2f285f6254ff (diff)
parent2ad52a506030d314a9113c7fcbd156029367b6af (diff)
Merge pull request #6867 from piwik/use_transientcache_once
Use transientcache once
-rw-r--r--core/SettingsPiwik.php96
-rw-r--r--tests/PHPUnit/Framework/Fixture.php1
2 files changed, 53 insertions, 44 deletions
diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php
index 1291c7fe13..5647fcb71e 100644
--- a/core/SettingsPiwik.php
+++ b/core/SettingsPiwik.php
@@ -10,6 +10,7 @@ namespace Piwik;
use Exception;
use Piwik\Container\StaticContainer;
+use Piwik\Cache as PiwikCache;
/**
* Contains helper methods that can be used to get common Piwik settings.
@@ -18,6 +19,7 @@ use Piwik\Container\StaticContainer;
class SettingsPiwik
{
const OPTION_PIWIK_URL = 'piwikUrl';
+
/**
* Get salt from [General] section
*
@@ -43,56 +45,54 @@ class SettingsPiwik
}
/**
- * @see getKnownSegmentsToArchive
- *
- * @var array
- */
- public static $cachedKnownSegmentsToArchive = null;
-
- /**
* Returns every stored segment to pre-process for each site during cron archiving.
*
* @return array The list of stored segments that apply to all sites.
*/
public static function getKnownSegmentsToArchive()
{
- if (self::$cachedKnownSegmentsToArchive === null) {
- $segments = Config::getInstance()->Segments;
- $segmentsToProcess = isset($segments['Segments']) ? $segments['Segments'] : array();
-
- /**
- * Triggered during the cron archiving process to collect segments that
- * should be pre-processed for all websites. The archiving process will be launched
- * for each of these segments when archiving data.
- *
- * This event can be used to add segments to be pre-processed. If your plugin depends
- * on data from a specific segment, this event could be used to provide enhanced
- * performance.
- *
- * _Note: If you just want to add a segment that is managed by the user, use the
- * SegmentEditor API._
- *
- * **Example**
- *
- * Piwik::addAction('Segments.getKnownSegmentsToArchiveAllSites', function (&$segments) {
- * $segments[] = 'country=jp;city=Tokyo';
- * });
- *
- * @param array &$segmentsToProcess List of segment definitions, eg,
- *
- * array(
- * 'browserCode=ff;resolution=800x600',
- * 'country=jp;city=Tokyo'
- * )
- *
- * Add segments to this array in your event handler.
- */
- Piwik::postEvent('Segments.getKnownSegmentsToArchiveAllSites', array(&$segmentsToProcess));
-
- self::$cachedKnownSegmentsToArchive = array_unique($segmentsToProcess);
+ $cacheId = 'KnownSegmentsToArchive';
+ $cache = PiwikCache::getTransientCache();
+ if ($cache->contains($cacheId)) {
+ return $cache->fetch($cacheId);
}
- return self::$cachedKnownSegmentsToArchive;
+ $segments = Config::getInstance()->Segments;
+ $segmentsToProcess = isset($segments['Segments']) ? $segments['Segments'] : array();
+
+ /**
+ * Triggered during the cron archiving process to collect segments that
+ * should be pre-processed for all websites. The archiving process will be launched
+ * for each of these segments when archiving data.
+ *
+ * This event can be used to add segments to be pre-processed. If your plugin depends
+ * on data from a specific segment, this event could be used to provide enhanced
+ * performance.
+ *
+ * _Note: If you just want to add a segment that is managed by the user, use the
+ * SegmentEditor API._
+ *
+ * **Example**
+ *
+ * Piwik::addAction('Segments.getKnownSegmentsToArchiveAllSites', function (&$segments) {
+ * $segments[] = 'country=jp;city=Tokyo';
+ * });
+ *
+ * @param array &$segmentsToProcess List of segment definitions, eg,
+ *
+ * array(
+ * 'browserCode=ff;resolution=800x600',
+ * 'country=jp;city=Tokyo'
+ * )
+ *
+ * Add segments to this array in your event handler.
+ */
+ Piwik::postEvent('Segments.getKnownSegmentsToArchiveAllSites', array(&$segmentsToProcess));
+
+ $segmentsToProcess = array_unique($segmentsToProcess);
+
+ $cache->save($cacheId, $segmentsToProcess);
+ return $segmentsToProcess;
}
/**
@@ -104,8 +104,13 @@ class SettingsPiwik
*/
public static function getKnownSegmentsToArchiveForSite($idSite)
{
- $segments = array();
+ $cacheId = 'KnownSegmentsToArchiveForSite' . $idSite;
+ $cache = PiwikCache::getTransientCache();
+ if ($cache->contains($cacheId)) {
+ return $cache->fetch($cacheId);
+ }
+ $segments = array();
/**
* Triggered during the cron archiving process to collect segments that
* should be pre-processed for one specific site. The archiving process will be launched
@@ -133,6 +138,11 @@ class SettingsPiwik
* @param int $idSite The ID of the site to get segments for.
*/
Piwik::postEvent('Segments.getKnownSegmentsToArchiveForSite', array(&$segments, $idSite));
+
+ $segments = array_unique($segments);
+
+ $cache->save($cacheId, $segments);
+
return $segments;
}
diff --git a/tests/PHPUnit/Framework/Fixture.php b/tests/PHPUnit/Framework/Fixture.php
index 4f7aac46fb..7435bcae47 100644
--- a/tests/PHPUnit/Framework/Fixture.php
+++ b/tests/PHPUnit/Framework/Fixture.php
@@ -223,7 +223,6 @@ class Fixture extends \PHPUnit_Framework_Assert
FakeAccess::$superUserLogin = 'superUserLogin';
- SettingsPiwik::$cachedKnownSegmentsToArchive = null;
File::$invalidateOpCacheBeforeRead = true;
if ($this->configureComponents) {