diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-03-31 00:40:53 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-03-31 05:27:06 +0300 |
commit | 12d9b392a9f2a8a867d04b7c3889cfc261b783b1 (patch) | |
tree | 2146491c239b3e63a3cb5ad11278f0c0af4a16da /core/Archive.php | |
parent | e4d1c8bdbe2f6adbe6c70f3a1289af4d66818348 (diff) |
A chunk implementation that is much simpler and makes more sense. Everything is now in the ArchiveWriter + Selector
Diffstat (limited to 'core/Archive.php')
-rw-r--r-- | core/Archive.php | 77 |
1 files changed, 13 insertions, 64 deletions
diff --git a/core/Archive.php b/core/Archive.php index c2316f21f0..e36619d119 100644 --- a/core/Archive.php +++ b/core/Archive.php @@ -595,24 +595,23 @@ class Archive $archiveNames = array($archiveNames); } - $chunk = new Chunk(); - - $chunks = array(); - // apply idSubtable if ($idSubtable !== null && $idSubtable != self::ID_SUBTABLE_LOAD_ALL_SUBTABLES ) { - foreach ($archiveNames as &$name) { - // to be backwards compatibe we need to look for the exact idSubtable blob and for the chunk - // that stores the subtables (a chunk stores many blobs in one blob) - $chunks[] = $this->appendIdSubtable($name, $chunk->getBlobIdForTable($idSubtable)); - $name = $this->appendIdsubtable($name, $idSubtable); + // this is also done in ArchiveSelector. It should be actually only done in ArchiveSelector but DataCollection + // does require to have the subtableId appended. Needs to be changed in refactoring to have it only in one + // place. + $dataNames = array(); + foreach ($archiveNames as $name) { + $dataNames[] = $this->appendIdsubtable($name, $idSubtable); } + } else { + $dataNames = $archiveNames; } $result = new Archive\DataCollection( - $archiveNames, $archiveDataType, $this->params->getIdSites(), $this->params->getPeriods(), $defaultRow = null); + $dataNames, $archiveDataType, $this->params->getIdSites(), $this->params->getPeriods(), $defaultRow = null); $archiveIds = $this->getArchiveIds($archiveNames); @@ -620,14 +619,7 @@ class Archive return $result; } - if (!empty($chunks)) { - // we cannot merge them to $archiveNames further up when generating the chunk names as the DataCollection - // would think that eg "chunk_0" is a subtable. - $archiveNames = array_merge($archiveNames, $chunks); - } - - $loadAllSubtables = $idSubtable == self::ID_SUBTABLE_LOAD_ALL_SUBTABLES; - $archiveData = ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $loadAllSubtables); + $archiveData = ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $idSubtable); foreach ($archiveData as $row) { // values are grouped by idsite (site ID), date1-date2 (date range), then name (field name) @@ -635,58 +627,20 @@ class Archive $periodStr = $row['date1'] . "," . $row['date2']; if ($archiveDataType == 'numeric') { - $value = $this->formatNumericValue($row['value']); + $row['value'] = $this->formatNumericValue($row['value']); } else { - $value = $this->uncompress($row['value']); $result->addMetadata($idSite, $periodStr, 'ts_archived', $row['ts_archived']); } $resultRow = & $result->get($idSite, $periodStr); - if ($chunk->isRecordNameAChunk($row['name'])) { - // one combined blob for all subtables - $value = unserialize($value); - - if (is_array($value)) { - $rawName = $chunk->getRecordNameWithoutChunkAppendix($row['name']); // eg PluginName_ArchiveName - - if ($loadAllSubtables) { - $this->moveAllBlobsWithinChunkToResultRow($resultRow, $rawName, $value); - } else { - $this->moveNeededBlobWithinChunkToResultRow($resultRow, $rawName, $idSubtable, $value); - } - } - - } else { - // one blob per datatable or subtable - $resultRow[$row['name']] = $value; - } - + // one blob per datatable or subtable + $resultRow[$row['name']] = $row['value']; } return $result; } - private function moveNeededBlobWithinChunkToResultRow(&$resultRow, $recordName, $idSubtable, $chunk) - { - $subtableRecordName = $this->appendIdSubtable($recordName, $idSubtable); - - if (array_key_exists($idSubtable, $chunk)) { - $resultRow[$subtableRecordName] = $chunk[$idSubtable]; - } else { - $resultRow[$subtableRecordName] = 0; - unset($resultRow['_metadata']); - } - } - - private function moveAllBlobsWithinChunkToResultRow(&$resultRow, $recordName, $chunk) - { - foreach ($chunk as $subtableId => $val) { - $subtableRecordName = $this->appendIdSubtable($recordName, $subtableId); - $resultRow[$subtableRecordName] = $val; - } - } - /** * Returns archive IDs for the sites, periods and archive names that are being * queried. This function will use the idarchive cache if it has the right data, @@ -865,11 +819,6 @@ class Archive return round((float)$value, 2); } - private function uncompress($data) - { - return @gzuncompress($data); - } - /** * Initializes the archive ID cache ($this->idarchives) for a particular 'done' flag. * |