Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2015-03-30 05:27:07 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-03-31 05:27:05 +0300
commitb6eb947f8a4220813e5fcd1eab080745b4bad13c (patch)
treecbf37437e35936d824be9375778755487d8d9e48 /core/DataTable.php
parent1a148fb681762d7177b7bda0fa852bb06492b79b (diff)
changed the name of chunks in archive tables, faster unserialization
Diffstat (limited to 'core/DataTable.php')
-rw-r--r--core/DataTable.php46
1 files changed, 42 insertions, 4 deletions
diff --git a/core/DataTable.php b/core/DataTable.php
index a668591221..efe05a4d7c 100644
--- a/core/DataTable.php
+++ b/core/DataTable.php
@@ -1276,6 +1276,33 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess
return $aSerializedDataTable;
}
+ private static $previousRowClasses = array('O:39:"Piwik\DataTable\Row\DataTableSummaryRow"', 'O:19:"Piwik\DataTable\Row"', 'O:36:"Piwik_DataTable_Row_DataTableSummary"', 'O:19:"Piwik_DataTable_Row"');
+ private static $rowClassToUseForUnserialize = 'O:29:"Piwik_DataTable_SerializedRow"';
+
+ /**
+ * It is faster to unserialize existing serialized Row instances to "Piwik_DataTable_SerializedRow" and access the
+ * `$row->c` property than implementing a "__wakeup" method in the Row instance to map the "$row->c" to $row->columns
+ * etc. We're talking here about 15% faster reports aggregation in some cases. To be concrete: We have a test where
+ * Archiving a year takes 1700 seconds with "__wakeup" and 1400 seconds with this method. Yes, it takes 300 seconds
+ * to wake up millions of rows. We should be able to remove this code here end 2015 and use the "__wakeup" way by then.
+ * Why? By then most new archives will have only arrays serialized anyway and therefore this mapping is rather an overhead.
+ *
+ * @param string $serialized
+ * @return array
+ * @throws Exception In case the unserialize fails
+ */
+ private function unserializeRows($serialized)
+ {
+ $serialized = str_replace(self::$previousRowClasses, self::$rowClassToUseForUnserialize, $serialized);
+ $rows = unserialize($serialized);
+
+ if ($rows === false) {
+ throw new Exception("The unserialization has failed!");
+ }
+
+ return $rows;
+ }
+
/**
* Adds a set of rows from a serialized DataTable string.
*
@@ -1289,13 +1316,24 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess
*/
public function addRowsFromSerializedArray($serialized)
{
- $rows = unserialize($serialized);
+ $rows = $this->unserializeRows($serialized);
- if ($rows === false) {
- throw new Exception("The unserialization has failed!");
+ if (array_key_exists(self::ID_SUMMARY_ROW, $rows)) {
+ if (is_array($rows[self::ID_SUMMARY_ROW])) {
+ $this->summaryRow = new Row($rows[self::ID_SUMMARY_ROW]);
+ } elseif (isset($rows[self::ID_SUMMARY_ROW]->c)) {
+ $this->summaryRow = new Row($rows[self::ID_SUMMARY_ROW]->c);
+ }
+ unset($rows[self::ID_SUMMARY_ROW]);
}
- $this->addRowsFromArray($rows);
+ foreach ($rows as $id => $row) {
+ if (isset($row->c)) {
+ $this->addRow(new Row($row->c));
+ } else {
+ $this->addRow(new Row($row));
+ }
+ }
}
/**