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:
authorThomas Steur <thomas.steur@googlemail.com>2014-12-22 01:43:30 +0300
committerThomas Steur <thomas.steur@googlemail.com>2014-12-22 01:43:30 +0300
commita1c74a9043812cd133d65a5a23a4a72ae0cf1928 (patch)
treefeee81716ff8d0920c42361701c6e5bae5b6efe0 /core/Archive.php
parentfb91155043c2dd269f32e27962e3cbdb00ad0aad (diff)
invalidate reports if needed when building an archive requested via web
Diffstat (limited to 'core/Archive.php')
-rw-r--r--core/Archive.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/core/Archive.php b/core/Archive.php
index b407465a45..76a619f0bb 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -10,8 +10,10 @@ namespace Piwik;
use Piwik\Archive\Parameters;
use Piwik\ArchiveProcessor\Rules;
+use Piwik\DataAccess\ArchiveInvalidator;
use Piwik\DataAccess\ArchiveSelector;
use Piwik\Period\Factory as PeriodFactory;
+use Piwik\Plugins\CoreAdminHome\API as CoreAdminHomeApi;
/**
* The **Archive** class is used to query cached analytics statistics
@@ -161,6 +163,11 @@ class Archive
private $params;
/**
+ * \Piwik\Cache\Cache
+ */
+ private static $cache;
+
+ /**
* @param Parameters $params
* @param bool $forceIndexedBySite Whether to force index the result of a query by site ID.
* @param bool $forceIndexedByDate Whether to force index the result of a query by period.
@@ -480,6 +487,32 @@ class Archive
return $recordName . "_" . $id;
}
+ private function invalidatedReportsIfNeeded()
+ {
+ if (is_null(self::$cache)) {
+ self::$cache = Cache::getTransientCache();
+ }
+
+ $id = 'Archive.RememberedReportsInvalidated';
+
+ if (self::$cache->contains($id)) {
+ return;
+ }
+
+ self::$cache->save($id, 1);
+
+ $invalidator = new ArchiveInvalidator();
+ $sitesPerDays = $invalidator->getRememberedArchivedReportsThatShouldBeInvalidated();
+
+ foreach ($sitesPerDays as $date => $siteIds) {
+ if (!empty($siteIds)) {
+ // an advanced version would only invalidate siteIds for $this->params->getIdSites() but would make
+ // everything way more complex eg the cache above and which siteIds we pass here...
+ CoreAdminHomeApi::getInstance()->invalidateArchivedReports($siteIds, $date);
+ }
+ }
+ }
+
/**
* Queries archive tables for data and returns the result.
* @param array|string $archiveNames
@@ -489,6 +522,8 @@ class Archive
*/
private function get($archiveNames, $archiveDataType, $idSubtable = null)
{
+ $this->invalidatedReportsIfNeeded();
+
if (!is_array($archiveNames)) {
$archiveNames = array($archiveNames);
}