diff --git a/core/Archive/ArchivePurger.php b/core/Archive/ArchivePurger.php index 59fc2c51f2e..9f13271248d 100644 --- a/core/Archive/ArchivePurger.php +++ b/core/Archive/ArchivePurger.php @@ -99,9 +99,6 @@ public function purgeInvalidatedArchivesFrom(Date $date) return 0; } - $emptyIdArchives = $this->model->getPlaceholderArchiveIds($numericTable); - $archiveIds = array_merge($archiveIds, $emptyIdArchives); - $this->logger->info("Found {countArchiveIds} invalidated archives safe to delete in {table}.", array( 'table' => $numericTable, 'countArchiveIds' => count($archiveIds) )); diff --git a/core/DataAccess/ArchiveSelector.php b/core/DataAccess/ArchiveSelector.php index ca29f4f7f43..9ad03ec8268 100644 --- a/core/DataAccess/ArchiveSelector.php +++ b/core/DataAccess/ArchiveSelector.php @@ -163,7 +163,6 @@ public static function getArchiveIds($siteIds, $periods, $segment, $plugins, $in FROM %s WHERE idsite IN (" . implode(',', $siteIds) . ") AND " . self::getNameCondition($plugins, $segment, $includeInvalidated) . " - AND ts_archived IS NOT NULL AND %s GROUP BY idsite, date1, date2"; diff --git a/core/DataAccess/Model.php b/core/DataAccess/Model.php index 451ef64b408..4323481b996 100644 --- a/core/DataAccess/Model.php +++ b/core/DataAccess/Model.php @@ -64,7 +64,6 @@ public function getInvalidatedArchiveIdsSafeToDelete($archiveTable, $setGroupCon GROUP_CONCAT(idarchive, '.', value ORDER BY ts_archived DESC) as archives FROM `$archiveTable` WHERE name LIKE 'done%' - AND ts_archived IS NOT NULL AND `value` NOT IN (" . ArchiveWriter::DONE_ERROR . ") GROUP BY idsite, date1, date2, period, name HAVING count(*) > 1"; @@ -108,14 +107,6 @@ public function getInvalidatedArchiveIdsSafeToDelete($archiveTable, $setGroupCon return $archiveIds; } - public function getPlaceholderArchiveIds($archiveTable) - { - $sql = "SELECT DISTINCT idarchive FROM `$archiveTable` WHERE ts_archived IS NULL"; - $result = Db::fetchAll($sql); - $result = array_column($result, 'idarchive'); - return $result; - } - public function updateArchiveAsInvalidated($archiveTable, $idSites, $allPeriodsToInvalidate, Segment $segment = null, $forceInvalidateNonexistentRanges = false, $name = null) { @@ -461,7 +452,6 @@ public function getArchiveIdAndVisits($numericTable, $idSite, $period, $dateStar AND arc1.period = ? AND ($sqlWhereArchiveName) $timeStampWhere - AND arc1.ts_archived IS NOT NULL ORDER BY arc1.ts_archived DESC, arc1.idarchive DESC"; $results = Db::fetchAll($sqlQuery, $bindSQL); diff --git a/core/Db/Schema/Mysql.php b/core/Db/Schema/Mysql.php index c64af3ed73d..b49c84ac1e7 100644 --- a/core/Db/Schema/Mysql.php +++ b/core/Db/Schema/Mysql.php @@ -298,7 +298,7 @@ public function getTablesCreateSql() ts_archived DATETIME NULL, value DOUBLE NULL, PRIMARY KEY(idarchive, name), - INDEX index_idsite_dates_period(idsite, date1, date2, period, ts_archived), + INDEX index_idsite_dates_period(idsite, date1, date2, period, name(6)), INDEX index_period_archived(period, ts_archived) ) ENGINE=$engine DEFAULT CHARSET=$charset ", diff --git a/core/Updates/5.0.0-b1.php b/core/Updates/5.0.0-b1.php index 8837881321e..6edc41d4c5c 100644 --- a/core/Updates/5.0.0-b1.php +++ b/core/Updates/5.0.0-b1.php @@ -10,6 +10,7 @@ namespace Piwik\Updates; +use Piwik\DataAccess\ArchiveTableCreator; use Piwik\Db; use Piwik\Common; use Piwik\Updater; @@ -44,17 +45,36 @@ public function doUpdate(Updater $updater) public function getMigrations(Updater $updater) { + $migrations = $this->getUpdateArchiveIndexMigrations(); + if ($this->requiresUpdatedLogVisitTableIndex()) { - return $this->getLogVisitTableMigrations(); + return $this->getLogVisitTableMigrations($migrations); } - return []; + return $migrations; } - private function getLogVisitTableMigrations() + private function getUpdateArchiveIndexMigrations() { $migrations = []; + $tables = ArchiveTableCreator::getTablesArchivesInstalled('numeric'); + foreach ($tables as $table) { + $migrations[] = $this->migration->db->sql(sprintf('DELETE FROM `%s` WHERE ts_archived is null', $table)); + + $hasPrefix = strpos($table, 'archive') !== 0; + if ($hasPrefix) { + $table = Common::unprefixTable($table); + } + $migrations[] = $this->migration->db->dropIndex($table, 'index_idsite_dates_period'); + $migrations[] = $this->migration->db->addIndex($table, ['idsite', 'date1', 'date2', 'period', 'name(6)'], 'index_idsite_dates_period'); + } + + return $migrations; + } + + private function getLogVisitTableMigrations($migrations) + { $migrations[] = $this->migration->db->dropIndex('log_visit', $this->indexName); // Using the custom `sql` method instead of the `addIndex` method as it doesn't support DESC collation @@ -88,4 +108,4 @@ private function requiresUpdatedLogVisitTableIndex() return true; } -} \ No newline at end of file +}