diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-07-23 02:21:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-23 02:21:00 +0300 |
commit | a50080b1814d0620978499e5421fffe5313433f6 (patch) | |
tree | 16e59dc9be45fd11778379df45314f0af751f602 /core/Archive.php | |
parent | 7faea0438eee8085fc15aa118fa166fa8ab60bab (diff) |
start working on db reader support (#14681)
Diffstat (limited to 'core/Archive.php')
-rw-r--r-- | core/Archive.php | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/core/Archive.php b/core/Archive.php index c268fbefdb..8d4b46e961 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -453,6 +453,31 @@ class Archive implements ArchiveQuery return $dataTable; } + private function canUseDbReader() + { + if (Common::isPhpCliMode() ) { + // we are likely archiving or we are in CronArchive class etc. where it is important to detect if a + // specific archive already exist or not to possibly prevent triggering an unneeded archive request... + // also we only want to read archives from the reader for requests from the web + return false; + } + + if (SettingsServer::isArchivePhpTriggered()) { + // when archiving is triggered, we want to make sure to read archives from master to ensure most recent + // archives are read etc + return false; + } + + if (Rules::isArchivingDisabledFor($this->params->getIdSites(), $this->params->getSegment(), $this->getPeriodLabel())) { + // in this case we know we won't be creating any archives and we will only want to read archives in order + // to present the data in Matomo. We want to use the reader in this case + return true; + } + + // archiving could be triggered during this request, better not use the reader + return false; + } + private function getSiteIdsThatAreRequestedInThisArchiveButWereNotInvalidatedYet() { if (is_null(self::$cache)) { @@ -556,7 +581,7 @@ class Archive implements ArchiveQuery return $result; } - $archiveData = ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $idSubtable); + $archiveData = ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $idSubtable, $this->canUseDbReader()); $isNumeric = $archiveDataType == 'numeric'; @@ -680,7 +705,7 @@ class Archive implements ArchiveQuery private function cacheArchiveIdsWithoutLaunching($plugins) { $idarchivesByReport = ArchiveSelector::getArchiveIds( - $this->params->getIdSites(), $this->params->getPeriods(), $this->params->getSegment(), $plugins); + $this->params->getIdSites(), $this->params->getPeriods(), $this->params->getSegment(), $plugins, $this->canUseDbReader()); // initialize archive ID cache for each report foreach ($plugins as $plugin) { |