From 5377425108efe04af89ab34c2da28d264541f082 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Mon, 7 Dec 2020 21:28:38 -0800 Subject: Avoid inserting duplicates in invalidation table to reduce IO. (#16843) * Avoid inserting duplicates in invalidation table to reduce IO. * Limit to given sites to not select too much. * fix build * tweaks to duplicate checking query * more pr feedback * fix cron archive test --- core/DataAccess/Model.php | 52 ++++- core/Db/BatchInsert.php | 3 + tests/PHPUnit/Integration/CronArchiveTest.php | 48 ++--- .../DataAccess/ArchiveInvalidatorTest.php | 210 +++++++++++++++++++++ 4 files changed, 281 insertions(+), 32 deletions(-) diff --git a/core/DataAccess/Model.php b/core/DataAccess/Model.php index 8f75740dd5..156cd14e8b 100644 --- a/core/DataAccess/Model.php +++ b/core/DataAccess/Model.php @@ -131,8 +131,9 @@ class Model FROM `$archiveTable` WHERE idsite IN (" . implode(',', $idSites) . ")"; + $periodCondition = ''; if (!empty($allPeriodsToInvalidate)) { - $sql .= " AND ("; + $periodCondition .= " AND ("; $isFirst = true; /** @var Period $period */ @@ -140,21 +141,22 @@ class Model if ($isFirst) { $isFirst = false; } else { - $sql .= " OR "; + $periodCondition .= " OR "; } if ($period->getLabel() == 'range') { // for ranges, we delete all ranges that contain the given date(s) - $sql .= "(period = " . (int)$period->getId() + $periodCondition .= "(period = " . (int)$period->getId() . " AND date2 >= '" . $period->getDateStart()->getDatetime() . "' AND date1 <= '" . $period->getDateEnd()->getDatetime() . "')"; } else { - $sql .= "(period = " . (int)$period->getId() + $periodCondition .= "(period = " . (int)$period->getId() . " AND date1 = '" . $period->getDateStart()->getDatetime() . "'" . " AND date2 = '" . $period->getDateEnd()->getDatetime() . "')"; } } - $sql .= ")"; + $periodCondition .= ")"; } + $sql .= $periodCondition; if (!empty($name)) { if (strpos($name, '.') !== false) { @@ -201,6 +203,8 @@ class Model $now = Date::now()->getDatetime(); + $existingInvalidations = $this->getExistingInvalidations($idSites, $periodCondition, $nameCondition); + $dummyArchives = []; foreach ($idSites as $idSite) { try { @@ -223,6 +227,12 @@ class Model $date1 = $period->getDateStart()->toString(); $date2 = $period->getDateEnd()->toString(); + + $key = $this->makeExistingInvalidationArrayKey($idSite, $date1, $date2, $period->getId(), $doneFlag); + if (!empty($existingInvalidations[$key])) { + continue; // avoid adding duplicates where possible + } + $idArchive = $archivesToCreateInvalidationRowsFor[$idSite][$period->getId()][$date1][$date2] ?? null; $dummyArchives[] = [ @@ -238,13 +248,39 @@ class Model } } - $fields = ['idarchive', 'name', 'report', 'idsite', 'date1', 'date2', 'period', 'ts_invalidated']; - - Db\BatchInsert::tableInsertBatch(Common::prefixTable('archive_invalidations'), $fields, $dummyArchives); + if (!empty($dummyArchives)) { + $fields = ['idarchive', 'name', 'report', 'idsite', 'date1', 'date2', 'period', 'ts_invalidated']; + Db\BatchInsert::tableInsertBatch(Common::prefixTable('archive_invalidations'), $fields, $dummyArchives); + } return count($idArchives); } + private function getExistingInvalidations($idSites, $periodCondition, $nameCondition) + { + $table = Common::prefixTable('archive_invalidations'); + + $idSites = array_map('intval', $idSites); + + $sql = "SELECT idsite, date1, date2, period, name, COUNT(*) as `count` FROM `$table` + WHERE idsite IN (" . implode(',', $idSites) . ") AND status = " . ArchiveInvalidator::INVALIDATION_STATUS_QUEUED . " + $periodCondition AND $nameCondition + GROUP BY idsite, date1, date2, period, name"; + $rows = Db::fetchAll($sql); + + $invalidations = []; + foreach ($rows as $row) { + $key = $this->makeExistingInvalidationArrayKey($row['idsite'], $row['date1'], $row['date2'], $row['period'], $row['name']); + $invalidations[$key] = $row['count']; + } + return $invalidations; + } + + private function makeExistingInvalidationArrayKey($idSite, $date1, $date2, $period, $name) + { + return implode('.', [$idSite, $date1, $date2, $period, $name]); + } + /** * @param string $archiveTable Prefixed table name * @param int[] $idSites diff --git a/core/Db/BatchInsert.php b/core/Db/BatchInsert.php index b980a818d2..6cb5729607 100644 --- a/core/Db/BatchInsert.php +++ b/core/Db/BatchInsert.php @@ -244,6 +244,9 @@ class BatchInsert } catch (Exception $e) { $code = $e->getCode(); $message = $e->getMessage() . ($code ? "[$code]" : ''); + if (\Piwik_ShouldPrintBackTraceWithMessage()) { + $message .= "\n" . $e->getTraceAsString(); + } $exceptions[] = "\n Try #" . (count($exceptions) + 1) . ': ' . $queryStart . ": " . $message; } } diff --git a/tests/PHPUnit/Integration/CronArchiveTest.php b/tests/PHPUnit/Integration/CronArchiveTest.php index d7eece38dd..00a8b4867e 100644 --- a/tests/PHPUnit/Integration/CronArchiveTest.php +++ b/tests/PHPUnit/Integration/CronArchiveTest.php @@ -697,48 +697,48 @@ Checking for queued invalidations... Segment "actions>=2" was created or changed recently and will therefore archive today (for site ID = 1) Segment "actions>=4" was created or changed recently and will therefore archive today (for site ID = 1) Done invalidating -Found invalidated archive we can skip (no visits): [idinvalidation = 75, idsite = 1, period = day(2020-02-03 - 2020-02-03), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 76, idsite = 1, period = week(2020-02-03 - 2020-02-09), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 74, idsite = 1, period = day(2020-02-02 - 2020-02-02), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 72, idsite = 1, period = day(2020-02-01 - 2020-02-01), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 73, idsite = 1, period = month(2020-02-01 - 2020-02-29), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 68, idsite = 1, period = week(2020-01-27 - 2020-02-02), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 65, idsite = 1, period = day(2020-01-01 - 2020-01-01), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 66, idsite = 1, period = month(2020-01-01 - 2020-01-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 67, idsite = 1, period = year(2020-01-01 - 2020-12-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 60, idsite = 1, period = day(2019-12-31 - 2019-12-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 58, idsite = 1, period = day(2019-12-30 - 2019-12-30), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 59, idsite = 1, period = week(2019-12-30 - 2020-01-05), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 56, idsite = 1, period = day(2019-12-23 - 2019-12-23), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 57, idsite = 1, period = week(2019-12-23 - 2019-12-29), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 54, idsite = 1, period = day(2019-12-16 - 2019-12-16), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Found invalidated archive we can skip (no visits): [idinvalidation = 55, idsite = 1, period = week(2019-12-16 - 2019-12-22), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 53, idsite = 1, period = day(2020-02-03 - 2020-02-03), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 54, idsite = 1, period = week(2020-02-03 - 2020-02-09), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 52, idsite = 1, period = day(2020-02-02 - 2020-02-02), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 50, idsite = 1, period = day(2020-02-01 - 2020-02-01), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 51, idsite = 1, period = month(2020-02-01 - 2020-02-29), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 46, idsite = 1, period = week(2020-01-27 - 2020-02-02), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 43, idsite = 1, period = day(2020-01-01 - 2020-01-01), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 44, idsite = 1, period = month(2020-01-01 - 2020-01-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 45, idsite = 1, period = year(2020-01-01 - 2020-12-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 35, idsite = 1, period = day(2019-12-31 - 2019-12-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 33, idsite = 1, period = day(2019-12-30 - 2019-12-30), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 34, idsite = 1, period = week(2019-12-30 - 2020-01-05), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 31, idsite = 1, period = day(2019-12-23 - 2019-12-23), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 32, idsite = 1, period = week(2019-12-23 - 2019-12-29), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 29, idsite = 1, period = day(2019-12-16 - 2019-12-16), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Found invalidated archive we can skip (no visits): [idinvalidation = 30, idsite = 1, period = week(2019-12-16 - 2019-12-22), name = donee0512c03f7c20af6ef96a8d792c6bb9f] Processing invalidation: [idinvalidation = 5, idsite = 1, period = day(2019-12-12 - 2019-12-12), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. -Processing invalidation: [idinvalidation = 17, idsite = 1, period = day(2019-12-11 - 2019-12-11), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. -Processing invalidation: [idinvalidation = 29, idsite = 1, period = day(2019-12-10 - 2019-12-10), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. +Processing invalidation: [idinvalidation = 14, idsite = 1, period = day(2019-12-11 - 2019-12-11), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. +Processing invalidation: [idinvalidation = 17, idsite = 1, period = day(2019-12-10 - 2019-12-10), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. Starting archiving for ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=day&date=2019-12-12&format=json&segment=actions%3E%3D2&trigger=archivephp Starting archiving for ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=day&date=2019-12-11&format=json&segment=actions%3E%3D2&trigger=archivephp Starting archiving for ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=day&date=2019-12-10&format=json&segment=actions%3E%3D2&trigger=archivephp Archived website id 1, period = day, date = 2019-12-12, segment = 'actions%3E%3D2', 0 visits found. Time elapsed: %fs Archived website id 1, period = day, date = 2019-12-11, segment = 'actions%3E%3D2', 0 visits found. Time elapsed: %fs Archived website id 1, period = day, date = 2019-12-10, segment = 'actions%3E%3D2', 0 visits found. Time elapsed: %fs -Found invalidated archive we can skip (no visits): [idinvalidation = 52, idsite = 1, period = day(2019-12-09 - 2019-12-09), name = donee0512c03f7c20af6ef96a8d792c6bb9f] -Processing invalidation: [idinvalidation = 53, idsite = 1, period = week(2019-12-09 - 2019-12-15), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. -Processing invalidation: [idinvalidation = 49, idsite = 1, period = day(2019-12-02 - 2019-12-02), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. +Found invalidated archive we can skip (no visits): [idinvalidation = 28, idsite = 1, period = day(2019-12-09 - 2019-12-09), name = donee0512c03f7c20af6ef96a8d792c6bb9f] +Processing invalidation: [idinvalidation = 6, idsite = 1, period = week(2019-12-09 - 2019-12-15), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. +Processing invalidation: [idinvalidation = 22, idsite = 1, period = day(2019-12-02 - 2019-12-02), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. No next invalidated archive. Starting archiving for ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=week&date=2019-12-09&format=json&segment=actions%3E%3D2&trigger=archivephp Starting archiving for ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=day&date=2019-12-02&format=json&segment=actions%3E%3D2&trigger=archivephp Archived website id 1, period = week, date = 2019-12-09, segment = 'actions%3E%3D2', 0 visits found. Time elapsed: %fs Archived website id 1, period = day, date = 2019-12-02, segment = 'actions%3E%3D2', 0 visits found. Time elapsed: %fs -Processing invalidation: [idinvalidation = 50, idsite = 1, period = week(2019-12-02 - 2019-12-08), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. +Processing invalidation: [idinvalidation = 23, idsite = 1, period = week(2019-12-02 - 2019-12-08), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. No next invalidated archive. Starting archiving for ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=week&date=2019-12-02&format=json&segment=actions%3E%3D2&trigger=archivephp Archived website id 1, period = week, date = 2019-12-02, segment = 'actions%3E%3D2', 0 visits found. Time elapsed: %fs -Processing invalidation: [idinvalidation = 51, idsite = 1, period = month(2019-12-01 - 2019-12-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. +Processing invalidation: [idinvalidation = 7, idsite = 1, period = month(2019-12-01 - 2019-12-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. No next invalidated archive. Starting archiving for ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=month&date=2019-12-01&format=json&segment=actions%3E%3D2&trigger=archivephp Archived website id 1, period = month, date = 2019-12-01, segment = 'actions%3E%3D2', 0 visits found. Time elapsed: %fs -Processing invalidation: [idinvalidation = 64, idsite = 1, period = year(2019-01-01 - 2019-12-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. +Processing invalidation: [idinvalidation = 8, idsite = 1, period = year(2019-01-01 - 2019-12-31), name = donee0512c03f7c20af6ef96a8d792c6bb9f]. No next invalidated archive. Starting archiving for ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=year&date=2019-01-01&format=json&segment=actions%3E%3D2&trigger=archivephp Archived website id 1, period = year, date = 2019-01-01, segment = 'actions%3E%3D2', 0 visits found. Time elapsed: %fs diff --git a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php index 9c9a4cb871..784146ce4f 100644 --- a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php +++ b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php @@ -1200,6 +1200,216 @@ class ArchiveInvalidatorTest extends IntegrationTestCase $expectedInvalidatedArchives, $report); } + public function test_markArchivesAsInvalidated_doesNotInsertDuplicateInvalidations() + { + $this->insertArchiveRowsForTest(); + + $segment = 'browserCode==IE'; + $segment = new Segment($segment, [1]); + + $segmentHash = $segment->getHash(); + + /** @var ArchiveInvalidator $archiveInvalidator */ + $archiveInvalidator = self::$fixture->piwikEnvironment->getContainer()->get('Piwik\Archive\ArchiveInvalidator'); + + $existingInvalidations = [ + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-03-02', 'date2' => '2020-03-08', 'period' => 2, 'report' => null], + + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-05-04', 'date2' => '2020-05-04', 'period' => 1, 'report' => null], + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-05-05', 'date2' => '2020-05-05', 'period' => 1, 'report' => null], + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-05-06', 'date2' => '2020-05-06', 'period' => 1, 'report' => null], + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-05-07', 'date2' => '2020-05-07', 'period' => 1, 'report' => null], + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-05-08', 'date2' => '2020-05-08', 'period' => 1, 'report' => null], + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-05-09', 'date2' => '2020-05-09', 'period' => 1, 'report' => null], + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-05-10', 'date2' => '2020-05-10', 'period' => 1, 'report' => null], + + ['name' => 'done' . $segmentHash, 'idsite' => 1, 'date1' => '2020-05-01', 'date2' => '2020-05-31', 'period' => 3, 'report' => null], + ]; + + $this->insertInvalidations($existingInvalidations); + + $archiveInvalidator->markArchivesAsInvalidated([1], ['2020-03-04', '2020-05-06'], 'week', + $segment, $cascadeDown = true, false); + + $expectedInvalidations = [ + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-02', + 'date2' => '2020-03-08', + 'period' => '2', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-04', + 'date2' => '2020-05-04', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-05', + 'date2' => '2020-05-05', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-06', + 'date2' => '2020-05-06', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-07', + 'date2' => '2020-05-07', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-08', + 'date2' => '2020-05-08', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-09', + 'date2' => '2020-05-09', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-10', + 'date2' => '2020-05-10', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-01', + 'date2' => '2020-05-31', + 'period' => '3', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-02', + 'date2' => '2020-03-02', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-01', + 'date2' => '2020-03-31', + 'period' => '3', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-03', + 'date2' => '2020-03-03', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-04', + 'date2' => '2020-03-04', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-05', + 'date2' => '2020-03-05', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-06', + 'date2' => '2020-03-06', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-07', + 'date2' => '2020-03-07', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-03-08', + 'date2' => '2020-03-08', + 'period' => '1', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-01-01', + 'date2' => '2020-12-31', + 'period' => '4', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + array ( + 'idarchive' => NULL, + 'idsite' => '1', + 'date1' => '2020-05-04', + 'date2' => '2020-05-10', + 'period' => '2', + 'name' => 'done5f4f9bafeda3443c3c2d4b2ef4dffadc', + 'report' => NULL, + ), + ]; + + $actualInvalidations = $this->getInvalidatedArchiveTableEntries(); + + $this->assertEquals($expectedInvalidations, $actualInvalidations); + } + public function test_reArchiveReport_createsCorrectInvalidationEntries_forAllSitesIfAllSpecified() { Date::$now = strtotime('2020-06-16 12:00:00'); -- cgit v1.2.3