From 3d3f3c0d9c79f75e05f7683197e53ac01064e3c6 Mon Sep 17 00:00:00 2001 From: mattab Date: Wed, 12 Mar 2014 21:24:24 +1300 Subject: Fixes #4768 Implement performance improvement for period=range: do not archive sub-tables (only the parent table). The sub-tables will be archived only when idSubtable is found, or flat=1, or expanded=1 --- core/ArchiveProcessor.php | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'core/ArchiveProcessor.php') diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php index f578673d01..20c4c2df80 100644 --- a/core/ArchiveProcessor.php +++ b/core/ArchiveProcessor.php @@ -199,8 +199,14 @@ class ArchiveProcessor $table = $this->aggregateDataTableRecord($recordName, $columnsAggregationOperation, $columnsToRenameAfterAggregation); - $nameToCount[$recordName]['level0'] = $table->getRowsCount(); - $nameToCount[$recordName]['recursive'] = $table->getRowsCountRecursive(); + $rowsCount = $table->getRowsCount(); + $nameToCount[$recordName]['level0'] = $rowsCount; + + $rowsCountRecursive = $rowsCount; + if($this->isAggregateSubTables()) { + $rowsCountRecursive = $table->getRowsCountRecursive(); + } + $nameToCount[$recordName]['recursive'] = $rowsCountRecursive; $blob = $table->getSerialized($maximumRowsInDataTableLevelZero, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation); Common::destroy($table); @@ -322,7 +328,15 @@ class ArchiveProcessor */ protected function aggregateDataTableRecord($name, $columnsAggregationOperation = null, $columnsToRenameAfterAggregation = null) { - $dataTable = $this->getArchive()->getDataTableExpanded($name, $idSubTable = null, $depth = null, $addMetadataSubtableId = false); + if($this->isAggregateSubTables()) { + // By default we shall aggregate all sub-tables. + $dataTable = $this->getArchive()->getDataTableExpanded($name, $idSubTable = null, $depth = null, $addMetadataSubtableId = false); + } else { + // In some cases (eg. Actions plugin when period=range), + // for better performance we will only aggregate the parent table + $dataTable = $this->getArchive()->getDataTable($name, $idSubTable = null); + } + $dataTable = $this->getAggregatedDataTableMap($dataTable, $columnsAggregationOperation); $this->renameColumnsAfterAggregation($dataTable, $columnsToRenameAfterAggregation); return $dataTable; @@ -402,7 +416,7 @@ class ArchiveProcessor // as $date => $tableToSum $this->aggregatedDataTableMapsAsOne($data, $table); } else { - $table->addDataTable($data); + $table->addDataTable($data, $this->isAggregateSubTables()); } return $table; } @@ -418,7 +432,7 @@ class ArchiveProcessor if($tableToAggregate instanceof Map) { $this->aggregatedDataTableMapsAsOne($tableToAggregate, $aggregated); } else { - $aggregated->addDataTable($tableToAggregate); + $aggregated->addDataTable($tableToAggregate, $this->isAggregateSubTables()); } } } @@ -430,7 +444,7 @@ class ArchiveProcessor $columnsToRenameAfterAggregation = self::$columnsToRenameAfterAggregation; } foreach ($columnsToRenameAfterAggregation as $oldName => $newName) { - $table->renameColumn($oldName, $newName); + $table->renameColumn($oldName, $newName, $this->isAggregateSubTables()); } } @@ -464,4 +478,12 @@ class ArchiveProcessor } return $metrics; } + + /** + * @return bool + */ + protected function isAggregateSubTables() + { + return !$this->getParams()->isSkipAggregationOfSubTables(); + } } -- cgit v1.2.3