getPurgeEstimate() 공개 정적인 메소드

The returned array maps table names with the number of rows that will be deleted. If the table name is mapped with -1, the table will be dropped.
public static getPurgeEstimate ( array $settings = null ) : array
$settings array The config options to use in the estimate. If null, the real options are used.
리턴 array
예제 #1
0
 protected function getDeleteDBSizeEstimate($getSettingsFromQuery = false, $forceEstimate = false)
 {
     $this->checkDataPurgeAdminSettingsIsEnabled();
     // get the purging settings & create two purger instances
     if ($getSettingsFromQuery) {
         $settings = $this->getPurgeSettingsFromRequest();
     } else {
         $settings = PrivacyManager::getPurgeDataSettings();
     }
     $doDatabaseSizeEstimate = PiwikConfig::getInstance()->Deletelogs['enable_auto_database_size_estimate'];
     // determine the DB size & purged DB size
     $metadataProvider = new MySQLMetadataProvider();
     $tableStatuses = $metadataProvider->getAllTablesStatus();
     $totalBytes = 0;
     foreach ($tableStatuses as $status) {
         $totalBytes += $status['Data_length'] + $status['Index_length'];
     }
     $result = array('currentSize' => MetricsFormatter::getPrettySizeFromBytes($totalBytes));
     // if the db size estimate feature is enabled, get the estimate
     if ($doDatabaseSizeEstimate || $forceEstimate == 1) {
         // maps tables whose data will be deleted with number of rows that will be deleted
         // if a value is -1, it means the table will be dropped.
         $deletedDataSummary = PrivacyManager::getPurgeEstimate($settings);
         $totalAfterPurge = $totalBytes;
         foreach ($tableStatuses as $status) {
             $tableName = $status['Name'];
             if (isset($deletedDataSummary[$tableName])) {
                 $tableTotalBytes = $status['Data_length'] + $status['Index_length'];
                 // if dropping the table
                 if ($deletedDataSummary[$tableName] === ReportsPurger::DROP_TABLE) {
                     $totalAfterPurge -= $tableTotalBytes;
                 } else {
                     if ($status['Rows'] > 0) {
                         $totalAfterPurge -= $tableTotalBytes / $status['Rows'] * $deletedDataSummary[$tableName];
                     }
                 }
             }
         }
         $result['sizeAfterPurge'] = MetricsFormatter::getPrettySizeFromBytes($totalAfterPurge);
         $result['spaceSaved'] = MetricsFormatter::getPrettySizeFromBytes($totalBytes - $totalAfterPurge);
     }
     return $result;
 }
예제 #2
0
 /**
  * Tests that purgeData works correctly when the 'keep segment reports' setting is set to true.
  *
  * @group Integration
  */
 public function testPurgeDataDeleteReportsKeepSegmentsReports()
 {
     PrivacyManager::savePurgeDataSettings(array('delete_reports_keep_day_reports' => 1, 'delete_reports_keep_segment_reports' => 1));
     // get purge data prediction
     $prediction = PrivacyManager::getPurgeEstimate();
     // perform checks on prediction
     $events = 3;
     // only the event action for the three purged day, dayAgo=x are purged (others are still in use)
     $expectedPrediction = array(Common::prefixTable('log_conversion') => 6, Common::prefixTable('log_link_visit_action') => 6 + $events, Common::prefixTable('log_visit') => 3, Common::prefixTable('log_conversion_item') => 3, Common::prefixTable('archive_numeric_2012_01') => -1, Common::prefixTable('archive_blob_2012_01') => 9);
     $this->assertEquals($expectedPrediction, $prediction);
     // purge data
     $this->_setTimeToRun();
     $this->assertTrue($this->instance->deleteLogData());
     $this->assertTrue($this->instance->deleteReportData());
     // perform checks
     $this->checkLogDataPurged();
     $this->_checkReportsAndMetricsPurged($janBlobsRemaining = 6, $janNumericRemaining = 70);
     // 1 segmented blob + 5 day blobs
 }