diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2020-11-23 04:18:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-23 04:18:29 +0300 |
commit | 9da2de3233592acc789eb61bdc775bd8ddf6b115 (patch) | |
tree | f12a4741048a81274cb4cf4b03e5adcac3493e8a | |
parent | 4cfbe93000e610bd152eb66e5b4a8874cd9304e2 (diff) |
Remove existing invalidations before scheduling new ones (#16772)4.0.0-rc7
-rw-r--r-- | core/Archive/ArchiveInvalidator.php | 7 | ||||
-rw-r--r-- | core/Version.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php | 19 |
3 files changed, 24 insertions, 4 deletions
diff --git a/core/Archive/ArchiveInvalidator.php b/core/Archive/ArchiveInvalidator.php index 95597dc480..2301c3ed97 100644 --- a/core/Archive/ArchiveInvalidator.php +++ b/core/Archive/ArchiveInvalidator.php @@ -544,12 +544,15 @@ class ArchiveInvalidator * since adding invalidations can take a long time and delay UI response times. * * @param int|int[]|'all' $idSites - * @param string $pluginName + * @param string|int $pluginName * @param string|null $report * @param Date|null $startDate */ - public function scheduleReArchiving($idSites, string $pluginName, string $report = null, Date $startDate = null) + public function scheduleReArchiving($idSites, string $pluginName, $report = null, Date $startDate = null) { + if (!empty($report)) { + $this->removeInvalidationsSafely($idSites, $pluginName, $report); + } try { $reArchiveList = new ReArchiveList($this->logger); $reArchiveList->add(json_encode([ diff --git a/core/Version.php b/core/Version.php index af3c4b5034..70f9c246eb 100644 --- a/core/Version.php +++ b/core/Version.php @@ -20,7 +20,7 @@ final class Version * The current Matomo version. * @var string */ - const VERSION = '4.0.0-rc6'; + const VERSION = '4.0.0-rc7'; const MAJOR_VERSION = 4; public function isStableVersion($version) diff --git a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php index 9aa35cd543..e2d2d59af0 100644 --- a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php +++ b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php @@ -1209,7 +1209,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase $this->invalidator->scheduleReArchiving('all', 'VisitsSummary'); $this->invalidator->applyScheduledReArchiving(); - $countInvalidations = Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('archive_invalidations')); + $countInvalidations = $this->getNumInvalidations(); $invalidationSites = Db::fetchAll("SELECT DISTINCT idsite FROM " . Common::prefixTable('archive_invalidations')); $invalidationSites = array_column($invalidationSites, 'idsite'); @@ -1218,6 +1218,23 @@ class ArchiveInvalidatorTest extends IntegrationTestCase $this->assertEquals([1,2,3,4,5,6,7,8,9,10], $invalidationSites); } + private function getNumInvalidations() + { + return Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('archive_invalidations')); + } + + public function test_scheduleReArchiving_cleanupWhenReportGiven() + { + $this->invalidator->scheduleReArchiving([1, 2, 3], 'ExamplePlugin', '5'); + $this->invalidator->applyScheduledReArchiving(); + $this->assertEquals(729, $this->getNumInvalidations()); + + $this->invalidator->scheduleReArchiving([1, 2, 3], 'ExamplePlugin', '5'); + $this->invalidator->applyScheduledReArchiving(); + // should not end up having twice the amount of invalidations but delete existing + $this->assertEquals(729, $this->getNumInvalidations()); + + } public function test_reArchiveReport_createsCorrectInvalidationEntries_ifNoReportSpecified() { Date::$now = strtotime('2020-06-16 12:00:00'); |