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 06:35:19 +0300
committerThomas Steur <thomas.steur@googlemail.com>2014-12-22 06:35:19 +0300
commit4e1563c553e8db798aa3f615abb6106336339eca (patch)
treea234c49b71b8b11ac5c12c41163bed11b38a7c2c /core/Archive.php
parent55fe05468d86dc51ad653b5de9bb4b9ad027ba78 (diff)
only invalidate reports for requested site ids for better performance
Diffstat (limited to 'core/Archive.php')
-rw-r--r--core/Archive.php44
1 files changed, 36 insertions, 8 deletions
diff --git a/core/Archive.php b/core/Archive.php
index dcc14b7ad0..eada3e2b53 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -486,19 +486,43 @@ class Archive
return $recordName . "_" . $id;
}
- private function invalidatedReportsIfNeeded()
+ private function getSiteIdsThatAreRequestedInThisArchiveButWereNotInvalidatedYet()
{
if (is_null(self::$cache)) {
self::$cache = Cache::getTransientCache();
}
- $id = 'Archive.RememberedReportsInvalidated';
+ $id = 'Archive.SiteIdsOfRememberedReportsInvalidated';
- if (self::$cache->contains($id)) {
- return;
+ if (!self::$cache->contains($id)) {
+ self::$cache->save($id, array());
}
- self::$cache->save($id, 1);
+ $siteIdsAlreadyHandled = self::$cache->fetch($id);
+ $siteIdsRequested = $this->params->getIdSites();
+
+ foreach ($siteIdsRequested as $index => $siteIdRequested) {
+ $siteIdRequested = (int) $siteIdRequested;
+
+ if (in_array($siteIdRequested, $siteIdsAlreadyHandled)) {
+ unset($siteIdsRequested[$index]); // was already handled previously, do not do it again
+ } else {
+ $siteIdsAlreadyHandled[] = $siteIdRequested; // we will handle this id this time
+ }
+ }
+
+ self::$cache->save($id, $siteIdsAlreadyHandled);
+
+ return $siteIdsRequested;
+ }
+
+ private function invalidatedReportsIfNeeded()
+ {
+ $siteIdsRequested = $this->getSiteIdsThatAreRequestedInThisArchiveButWereNotInvalidatedYet();
+
+ if (empty($siteIdsRequested)) {
+ return; // all requested site ids were already handled
+ }
$invalidator = new ArchiveInvalidator();
$sitesPerDays = $invalidator->getRememberedArchivedReportsThatShouldBeInvalidated();
@@ -508,10 +532,14 @@ class Archive
continue;
}
+ $siteIdsToActuallyInvalidate = array_intersect($siteIds, $siteIdsRequested);
+
+ if (empty($siteIdsToActuallyInvalidate)) {
+ continue; // all site ids that should be handled are already handled
+ }
+
try {
- // 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...
- $invalidator->markArchivesAsInvalidated($siteIds, $date, false);
+ $invalidator->markArchivesAsInvalidated($siteIdsToActuallyInvalidate, $date, false);
} catch (\Exception $e) {
Site::clearCache();
throw $e;