diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-04-08 08:00:41 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-04-21 06:20:26 +0300 |
commit | 04b931a2e03d0ac2d157bc35c7b8e6f20cd0624b (patch) | |
tree | 711ae97dac7a8810605bed20a2bef67efd5ed2b7 /core/Archive.php | |
parent | 1cfdd56b16ced85c96eadb60d71b9156b4ae0a65 (diff) |
improve performance of all websites dashboard when having thousands of websites
Diffstat (limited to 'core/Archive.php')
-rw-r--r-- | core/Archive.php | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/core/Archive.php b/core/Archive.php index 5178718e73..8026fc0f5b 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -357,6 +357,20 @@ class Archive } /** + * Similar to {@link getDataTableFromNumeric()} but merges all children on the created DataTable. + * + * This is the same as doing `$this->getDataTableFromNumeric()->mergeChildren()` but this way it is much faster. + * + * @return DataTable|DataTable\Map + */ + public function getDataTableFromNumericAndMergeChildren($names) + { + $data = $this->get($names, 'numeric'); + $resultIndexes = $this->getResultIndices(); + return $data->getMergedDataTable($resultIndexes); + } + + /** * Queries and returns one or more reports as DataTable instances. * * This method will query blob data that is a serialized array of of {@link DataTable\Row}'s and @@ -616,21 +630,19 @@ class Archive $archiveData = ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $idSubtable); + $isNumeric = $archiveDataType == 'numeric'; + foreach ($archiveData as $row) { // values are grouped by idsite (site ID), date1-date2 (date range), then name (field name) - $idSite = $row['idsite']; - $periodStr = $row['date1'] . "," . $row['date2']; + $periodStr = $row['date1'] . ',' . $row['date2']; - if ($archiveDataType == 'numeric') { + if ($isNumeric) { $row['value'] = $this->formatNumericValue($row['value']); } else { - $result->addMetadata($idSite, $periodStr, 'ts_archived', $row['ts_archived']); + $result->addMetadata($row['idsite'], $periodStr, 'ts_archived', $row['ts_archived']); } - $resultRow = & $result->get($idSite, $periodStr); - - // one blob per datatable or subtable - $resultRow[$row['name']] = $row['value']; + $result->set($row['idsite'], $periodStr, $row['name'], $row['value']); } return $result; |