From b53839f7e40f584066c13f60e5b37542b3c10cad Mon Sep 17 00:00:00 2001 From: mattab <matthieu.aubry@gmail.com> Date: Fri, 7 Jun 2013 12:55:46 +1200 Subject: [PATCH] removing destroy() calls --- core/PluginsArchiver.php | 1 + plugins/Actions/Archiver.php | 92 ++++++++++++++++++++------------ plugins/UserCountry/Archiver.php | 10 ++-- 3 files changed, 62 insertions(+), 41 deletions(-) diff --git a/core/PluginsArchiver.php b/core/PluginsArchiver.php index d29497f042..dca85a7c77 100644 --- a/core/PluginsArchiver.php +++ b/core/PluginsArchiver.php @@ -19,6 +19,7 @@ abstract class Piwik_PluginsArchiver public function __construct(Piwik_ArchiveProcessing $processing) { + $this->maximumRows = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_standard']; $this->processor = $processing; } diff --git a/plugins/Actions/Archiver.php b/plugins/Actions/Archiver.php index 7e04246f83..e8a4855463 100644 --- a/plugins/Actions/Archiver.php +++ b/plugins/Actions/Archiver.php @@ -411,49 +411,37 @@ class Piwik_Actions_Archiver extends Piwik_PluginsArchiver { Piwik_Actions_ArchivingHelper::clearActionsCache(); - /** @var Piwik_DataTable $dataTable */ - $dataTable = $this->actionsTablesByType[Piwik_Tracker_Action::TYPE_ACTION_URL]; - self::deleteInvalidSummedColumnsFromDataTable($dataTable); - $s = $dataTable->getSerialized(Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero, Piwik_Actions_ArchivingHelper::$maximumRowsInSubDataTable, Piwik_Actions_ArchivingHelper::$columnToSortByBeforeTruncation); - $this->getProcessor()->insertBlobRecord('Actions_actions_url', $s); + $this->recordPageUrlsReports(); + $this->recordDownloadsReports(); + $this->recordOutlinksReports(); + $this->recordPageTitlesReports(); + $this->recordSiteSearchReports(); + } + + protected function recordPageUrlsReports() + { + $dataTable = $this->getDataTable(Piwik_Tracker_Action::TYPE_ACTION_URL); + $this->recordDataTable($dataTable, 'Actions_actions_url'); $this->getProcessor()->insertNumericRecord('Actions_nb_pageviews', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_PAGE_NB_HITS))); $this->getProcessor()->insertNumericRecord('Actions_nb_uniq_pageviews', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS))); $this->getProcessor()->insertNumericRecord('Actions_sum_time_generation', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_PAGE_SUM_TIME_GENERATION))); $this->getProcessor()->insertNumericRecord('Actions_nb_hits_with_time_generation', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_PAGE_NB_HITS_WITH_TIME_GENERATION))); - destroy($dataTable); - - $dataTable = $this->actionsTablesByType[Piwik_Tracker_Action::TYPE_DOWNLOAD]; - self::deleteInvalidSummedColumnsFromDataTable($dataTable); - $s = $dataTable->getSerialized(Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero, Piwik_Actions_ArchivingHelper::$maximumRowsInSubDataTable, Piwik_Actions_ArchivingHelper::$columnToSortByBeforeTruncation); - $this->getProcessor()->insertBlobRecord('Actions_downloads', $s); - $this->getProcessor()->insertNumericRecord('Actions_nb_downloads', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_PAGE_NB_HITS))); - $this->getProcessor()->insertNumericRecord('Actions_nb_uniq_downloads', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS))); - destroy($dataTable); - - $dataTable = $this->actionsTablesByType[Piwik_Tracker_Action::TYPE_OUTLINK]; - self::deleteInvalidSummedColumnsFromDataTable($dataTable); - $s = $dataTable->getSerialized(Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero, Piwik_Actions_ArchivingHelper::$maximumRowsInSubDataTable, Piwik_Actions_ArchivingHelper::$columnToSortByBeforeTruncation); - $this->getProcessor()->insertBlobRecord('Actions_outlink', $s); - $this->getProcessor()->insertNumericRecord('Actions_nb_outlinks', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_PAGE_NB_HITS))); - $this->getProcessor()->insertNumericRecord('Actions_nb_uniq_outlinks', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS))); - destroy($dataTable); + } - $dataTable = $this->actionsTablesByType[Piwik_Tracker_Action::TYPE_ACTION_NAME]; - self::deleteInvalidSummedColumnsFromDataTable($dataTable); - $s = $dataTable->getSerialized(Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero, Piwik_Actions_ArchivingHelper::$maximumRowsInSubDataTable, Piwik_Actions_ArchivingHelper::$columnToSortByBeforeTruncation); - $this->getProcessor()->insertBlobRecord('Actions_actions', $s); - destroy($dataTable); + /** + * @param $typeId + * @return Piwik_DataTable + */ + protected function getDataTable($typeId) + { + return $this->actionsTablesByType[$typeId]; + } - $dataTable = $this->actionsTablesByType[Piwik_Tracker_Action::TYPE_SITE_SEARCH]; + protected function recordDataTable($dataTable, $recordName) + { self::deleteInvalidSummedColumnsFromDataTable($dataTable); - $this->deleteUnusedColumnsFromKeywordsDataTable($dataTable); $s = $dataTable->getSerialized(Piwik_Actions_ArchivingHelper::$maximumRowsInDataTableLevelZero, Piwik_Actions_ArchivingHelper::$maximumRowsInSubDataTable, Piwik_Actions_ArchivingHelper::$columnToSortByBeforeTruncation); - $this->getProcessor()->insertBlobRecord('Actions_sitesearch', $s); - $this->getProcessor()->insertNumericRecord('Actions_nb_searches', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS))); - $this->getProcessor()->insertNumericRecord('Actions_nb_keywords', $dataTable->getRowsCount()); - destroy($dataTable); - - destroy($this->actionsTablesByType); + $this->getProcessor()->insertBlobRecord($recordName, $s); } /** @@ -497,6 +485,40 @@ class Piwik_Actions_Archiver extends Piwik_PluginsArchiver )); } + protected function recordDownloadsReports() + { + $dataTable = $this->getDataTable(Piwik_Tracker_Action::TYPE_DOWNLOAD); + $this->recordDataTable($dataTable, 'Actions_downloads'); + + $this->getProcessor()->insertNumericRecord('Actions_nb_downloads', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_PAGE_NB_HITS))); + $this->getProcessor()->insertNumericRecord('Actions_nb_uniq_downloads', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS))); + } + + protected function recordOutlinksReports() + { + $dataTable = $this->getDataTable(Piwik_Tracker_Action::TYPE_OUTLINK); + $this->recordDataTable($dataTable, 'Actions_outlink'); + + $this->getProcessor()->insertNumericRecord('Actions_nb_outlinks', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_PAGE_NB_HITS))); + $this->getProcessor()->insertNumericRecord('Actions_nb_uniq_outlinks', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS))); + } + + protected function recordPageTitlesReports() + { + $dataTable = $this->getDataTable(Piwik_Tracker_Action::TYPE_ACTION_NAME); + $this->recordDataTable($dataTable, 'Actions_actions'); + } + + protected function recordSiteSearchReports() + { + $dataTable = $this->getDataTable(Piwik_Tracker_Action::TYPE_SITE_SEARCH); + $this->deleteUnusedColumnsFromKeywordsDataTable($dataTable); + $this->recordDataTable($dataTable, 'Actions_sitesearch'); + + $this->getProcessor()->insertNumericRecord('Actions_nb_searches', array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS))); + $this->getProcessor()->insertNumericRecord('Actions_nb_keywords', $dataTable->getRowsCount()); + } + protected function deleteUnusedColumnsFromKeywordsDataTable($dataTable) { $columnsToDelete = array( diff --git a/plugins/UserCountry/Archiver.php b/plugins/UserCountry/Archiver.php index bdd7c10f02..99bd1e40a1 100644 --- a/plugins/UserCountry/Archiver.php +++ b/plugins/UserCountry/Archiver.php @@ -23,6 +23,8 @@ class Piwik_UserCountry_Archiver extends Piwik_PluginsArchiver private $metricsByDimension = array(); + protected $maximumRows; + public function archiveDay() { $this->metricsByDimension = array('location_country' => array(), @@ -145,23 +147,19 @@ class Piwik_UserCountry_Archiver extends Piwik_PluginsArchiver protected function recordDayReports() { - $maximumRows = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_standard']; - $tableCountry = Piwik_ArchiveProcessing_Day::getDataTableFromArray($this->metricsByDimension['location_country']); $this->getProcessor()->insertBlobRecord(self::VISITS_BY_COUNTRY_RECORD_NAME, $tableCountry->getSerialized()); $this->getProcessor()->insertNumericRecord(self::DISTINCT_COUNTRIES_METRIC, $tableCountry->getRowsCount()); destroy($tableCountry); $tableRegion = Piwik_ArchiveProcessing_Day::getDataTableFromArray($this->metricsByDimension['location_region']); - $serialized = $tableRegion->getSerialized($maximumRows, $maximumRows, Piwik_Archive::INDEX_NB_VISITS); + $serialized = $tableRegion->getSerialized($this->maximumRows, $this->maximumRows, Piwik_Archive::INDEX_NB_VISITS); $this->getProcessor()->insertBlobRecord(self::VISITS_BY_REGION_RECORD_NAME, $serialized); - destroy($tableRegion); $tableCity = Piwik_ArchiveProcessing_Day::getDataTableFromArray($this->metricsByDimension['location_city']); $this->setLatitudeLongitude($tableCity); - $serialized = $tableCity->getSerialized($maximumRows, $maximumRows, Piwik_Archive::INDEX_NB_VISITS); + $serialized = $tableCity->getSerialized($this->maximumRows, $this->maximumRows, Piwik_Archive::INDEX_NB_VISITS); $this->getProcessor()->insertBlobRecord(self::VISITS_BY_CITY_RECORD_NAME, $serialized); - destroy($tableCity); } /** -- GitLab