diff options
author | diosmosis <benaka@piwik.pro> | 2015-10-08 03:32:08 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-10-12 21:05:37 +0300 |
commit | c186252bf9a30a54c15330f0f4c88c1a033e7f25 (patch) | |
tree | d3c288649d36b242844129a1aea8fb3ec3488a12 /core | |
parent | b588b2bce30e0da5283eea0d5b1830e6fe8bf761 (diff) |
Fix regression, make sure if period is not supplied to ArchiveInvalidator then all periods are invalidated efficiently.
Diffstat (limited to 'core')
-rw-r--r-- | core/Archive/ArchiveInvalidator.php | 51 | ||||
-rw-r--r-- | core/DataAccess/Model.php | 19 |
2 files changed, 51 insertions, 19 deletions
diff --git a/core/Archive/ArchiveInvalidator.php b/core/Archive/ArchiveInvalidator.php index daa847e520..c4fff2bef4 100644 --- a/core/Archive/ArchiveInvalidator.php +++ b/core/Archive/ArchiveInvalidator.php @@ -137,11 +137,16 @@ class ArchiveInvalidator $datesToInvalidate = $this->removeDatesThatHaveBeenPurged($dates, $invalidationInfo); - $periods = $this->getPeriodsToInvalidate($datesToInvalidate, $period, $cascadeDown); - $periods = $this->getPeriodsByYearMonthAndType($periods); - $this->markArchivesInvalidated($idSites, $periods, $segment); + if (empty($period)) { + // if the period is empty, we don't need to cascade in any way, since we'll remove all periods + $periodDates = $this->getDatesByYearMonthAndPeriodType($dates); + } else { + $periods = $this->getPeriodsToInvalidate($datesToInvalidate, $period, $cascadeDown); + $periodDates = $this->getPeriodDatesByYearMonthAndPeriodType($periods); + } + $this->markArchivesInvalidated($idSites, $periodDates, $segment); - $yearMonths = array_keys($periods); + $yearMonths = array_keys($periodDates); $this->markInvalidatedArchivesForReprocessAndPurge($idSites, $yearMonths); foreach ($idSites as $idSite) { @@ -197,35 +202,57 @@ class ArchiveInvalidator /** * @param Period[] $periods - * @return Period[][][] + * @return string[][][] */ - private function getPeriodsByYearMonthAndType($periods) + private function getPeriodDatesByYearMonthAndPeriodType($periods) { $result = array(); foreach ($periods as $period) { - $yearMonth = ArchiveTableCreator::getTableMonthFromDate($period->getDateStart()); + $date = $period->getDateStart(); $periodType = $period->getId(); - $result[$yearMonth][$periodType][] = $period; + $yearMonth = ArchiveTableCreator::getTableMonthFromDate($date); + $result[$yearMonth][$periodType][] = $date->toString(); + } + return $result; + } + + /** + * Called when deleting all periods. + * + * @param Date[] $dates + * @return string[][][] + */ + private function getDatesByYearMonthAndPeriodType($dates) + { + $result = array(); + foreach ($dates as $date) { + $yearMonth = ArchiveTableCreator::getTableMonthFromDate($date); + $result[$yearMonth][null][] = $date->toString(); + + // since we're removing all periods, we must make sure to remove year periods as well. + // this means we have to make sure the january table is processed. + $janYearMonth = $date->toString('Y') . '_01'; + $result[$janYearMonth][null][] = $date->toString(); } return $result; } /** * @param int[] $idSites - * @param Period[][][] $periods + * @param string[][][] $dates * @throws \Exception */ - private function markArchivesInvalidated($idSites, $periods, Segment $segment = null) + private function markArchivesInvalidated($idSites, $dates, Segment $segment = null) { $archiveNumericTables = ArchiveTableCreator::getTablesArchivesInstalled($type = ArchiveTableCreator::NUMERIC_TABLE); foreach ($archiveNumericTables as $table) { $tableDate = ArchiveTableCreator::getDateFromTableName($table); - if (empty($periods[$tableDate])) { + if (empty($dates[$tableDate])) { continue; } - $this->model->updateArchiveAsInvalidated($table, $idSites, $periods[$tableDate], $segment); + $this->model->updateArchiveAsInvalidated($table, $idSites, $dates[$tableDate], $segment); } } diff --git a/core/DataAccess/Model.php b/core/DataAccess/Model.php index f70a934d13..e8ec27c7de 100644 --- a/core/DataAccess/Model.php +++ b/core/DataAccess/Model.php @@ -100,28 +100,33 @@ class Model /** * @param string $archiveTable Prefixed table name * @param int[] $idSites - * @param Period[][] $periodsByType + * @param string[][] $datesByPeriodType * @param Segment $segment * @return \Zend_Db_Statement * @throws Exception */ - public function updateArchiveAsInvalidated($archiveTable, $idSites, $periodsByType, Segment $segment = null) + public function updateArchiveAsInvalidated($archiveTable, $idSites, $datesByPeriodType, Segment $segment = null) { $idSites = array_map('intval', $idSites); $bind = array(); $periodConditions = array(); - foreach ($periodsByType as $periodType => $periods) { + foreach ($datesByPeriodType as $periodType => $dates) { $dateConditions = array(); - foreach ($periods as $period) { + foreach ($dates as $date) { $dateConditions[] = "(date1 <= ? AND ? <= date2)"; - $bind[] = $period->getDateStart()->toString(); - $bind[] = $period->getDateStart()->toString(); + $bind[] = $date; + $bind[] = $date; } - $periodConditions[] = "(period = " . (int)$periodType . " AND (" . implode(" OR ", $dateConditions) . "))"; + $dateConditionsSql = implode(" OR ", $dateConditions); + if (empty($periodType)) { // remove all periods + $periodConditions[] = "($dateConditionsSql)"; + } else { + $periodConditions[] = "(period = " . (int)$periodType . " AND ($dateConditionsSql))"; + } } if ($segment) { |