diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2021-05-12 02:34:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 02:34:33 +0300 |
commit | c0a78e001399c596da3b4ecb23032bfab6c48fc9 (patch) | |
tree | c95ef55ff9def9aee2b09dc2f43f484dab5c52b3 | |
parent | ba6be4072538eaf54625ebfcead626107836c818 (diff) |
If no archives names are requested when querying archive data, do not initiate archiving. (#17547)4.3.0-rc2
* If no archives names are requested when querying archive data, do not initiate archiving.
* apply pr feedback
-rw-r--r-- | core/Archive.php | 5 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/ArchiveTest.php | 28 |
2 files changed, 33 insertions, 0 deletions
diff --git a/core/Archive.php b/core/Archive.php index 38f8d63b0d..8da0747635 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -476,6 +476,8 @@ class Archive implements ArchiveQuery $archiveNames = array($archiveNames); } + $archiveNames = array_filter($archiveNames); + // apply idSubtable if ($idSubtable !== null && $idSubtable !== self::ID_SUBTABLE_LOAD_ALL_SUBTABLES @@ -493,6 +495,9 @@ class Archive implements ArchiveQuery $result = new Archive\DataCollection( $dataNames, $archiveDataType, $this->params->getIdSites(), $this->params->getPeriods(), $this->params->getSegment(), $defaultRow = null); + if (empty($dataNames)) { + return $result; // NOTE: note posting Archive.noArchivedData here, because there might be archive data, someone just requested nothing + } $archiveIds = $this->getArchiveIds($archiveNames); if (empty($archiveIds)) { diff --git a/tests/PHPUnit/Integration/ArchiveTest.php b/tests/PHPUnit/Integration/ArchiveTest.php index 66ecd17355..1e274431d7 100644 --- a/tests/PHPUnit/Integration/ArchiveTest.php +++ b/tests/PHPUnit/Integration/ArchiveTest.php @@ -15,6 +15,7 @@ use Piwik\ArchiveProcessor\Rules; use Piwik\Common; use Piwik\Config; use Piwik\CronArchive; +use Piwik\DataAccess\ArchiveTableCreator; use Piwik\DataAccess\ArchiveWriter; use Piwik\Date; use Piwik\Db; @@ -34,6 +35,33 @@ class ArchiveTest extends IntegrationTestCase Fixture::createWebsite('2014-05-06'); } + public function test_queryingForNoData_doesNotCreateEmptyArchive() + { + $tracker = Fixture::getTracker(1, '2014-05-07 07:00:00'); + $tracker->setUrl('http://matomo.net/page/1'); + Fixture::checkResponse($tracker->doTrackPageView('a page')); + + $tracker->setForceVisitDateTime('2014-05-08 09:00:00'); + $tracker->setUrl('http://matomo.net/page/2'); + Fixture::checkResponse($tracker->doTrackPageView('a page')); + + // the table may not be created if we skip archiving logic, so make sure it's created here + ArchiveTableCreator::getNumericTable(Date::factory('2014-05-07')); + + $archive = Archive::factory(new Segment('', [1]), [Factory::build('range', '2014-05-07,2014-05-08')], [1]); + $data = $archive->getDataTableFromNumeric([]); + $this->assertEquals([], $data->getRows()); + + $data = $archive->getDataTableFromNumeric(null); + $this->assertEquals([], $data->getRows()); + + $data = $archive->getDataTableFromNumeric(['']); + $this->assertEquals([], $data->getRows()); + + $archiveRows = Db::fetchAll('SELECT * FROM ' . Common::prefixTable('archive_numeric_2014_05') . ' WHERE idsite = 1 AND period = 5'); + $this->assertEquals([], $archiveRows); + } + public function test_pluginSpecificArchiveUsed_EvenIfAllArchiveExists_IfThereAreNoDataInAllArchive() { $idSite = 1; |