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
path: root/core
diff options
context:
space:
mode:
authormatt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105>2009-04-07 05:20:52 +0400
committermatt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105>2009-04-07 05:20:52 +0400
commit5a61b80a9a4245910bca25be7942aa45d204483c (patch)
treef4c1476af1221b49f4ff5ac88df5aa59c9d6fe37 /core
parentb885a9cbb2f1028403d39904f585a5d2c1ec4c8a (diff)
- fixes #577 Aautomatic purge should be automatically called once a day on every archive table
Diffstat (limited to 'core')
-rw-r--r--core/ArchiveProcessing/Day.php30
-rw-r--r--core/ArchiveProcessing/Period.php30
2 files changed, 23 insertions, 37 deletions
diff --git a/core/ArchiveProcessing/Day.php b/core/ArchiveProcessing/Day.php
index 5050d8fd6a..7fcc512c46 100644
--- a/core/ArchiveProcessing/Day.php
+++ b/core/ArchiveProcessing/Day.php
@@ -79,36 +79,6 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing
}
/**
- * Called at the end of the archiving process.
- * Does some cleaning job in the database.
- *
- * @return void
- */
- protected function postCompute()
- {
- parent::postCompute();
-
- //TODO should be done in a different asynchronous job
- if(rand(0, 15) == 5)
- {
- // we delete out of date records
- // = archives that for day N computed on day N (means they are only partial)
- $blobTable = $this->tableArchiveBlob->getTableName();
- $numericTable = $this->tableArchiveNumeric->getTableName();
-
- $query = "/* SHARDING_ID_SITE = ".$this->idsite." */ DELETE
- FROM %s
- WHERE period = ?
- AND date1 = DATE(ts_archived)
- AND DATE(ts_archived) <> CURRENT_DATE()
- ";
-
- Zend_Registry::get('db')->query(sprintf($query, $blobTable), $this->periodId);
- Zend_Registry::get('db')->query(sprintf($query, $numericTable), $this->periodId);
- }
- }
-
- /**
* Helper function that returns a DataTable containing the $select fields / value pairs.
* IMPORTANT: The $select must return only one row!!
*
diff --git a/core/ArchiveProcessing/Period.php b/core/ArchiveProcessing/Period.php
index d1e60db76e..e2bcfda5c9 100644
--- a/core/ArchiveProcessing/Period.php
+++ b/core/ArchiveProcessing/Period.php
@@ -287,15 +287,29 @@ class Piwik_ArchiveProcessing_Period extends Piwik_ArchiveProcessing
{
parent::postCompute();
- //TODO should be done in a different asynchronous job
- if(rand(0, 15) == 5)
+ $blobTable = $this->tableArchiveBlob->getTableName();
+ $numericTable = $this->tableArchiveNumeric->getTableName();
+
+ // delete out of date records maximum once per day (DELETE request is costly)
+ $key = 'lastPurge_' . $blobTable;
+ $timestamp = Piwik_GetOption($key);
+ if(!$timestamp
+ || $timestamp < time() - 86400 )
{
- // we delete records that are now out of date
- // in the case of a period we delete archives that were archived before the end of the period
- // and only if they are at least 1 day old (so we don't delete archives computed today that may be stil valid)
- $blobTable = $this->tableArchiveBlob->getTableName();
- $numericTable = $this->tableArchiveNumeric->getTableName();
+ // we delete out of date daily archives from table, maximum once per day
+ // those for day N that were processed on day N (means the archives are only partial as the day wasn't finished)
+ $query = "/* SHARDING_ID_SITE = ".$this->idsite." */ DELETE
+ FROM %s
+ WHERE period = ?
+ AND date1 = DATE(ts_archived)
+ AND DATE(ts_archived) <> CURRENT_DATE()
+ ";
+ Zend_Registry::get('db')->query(sprintf($query, $blobTable), Piwik::$idPeriods['day']);
+ Zend_Registry::get('db')->query(sprintf($query, $numericTable), Piwik::$idPeriods['day']);
+ // we delete out of date Period records (week/month/etc)
+ // we delete archives that were archived before the end of the period
+ // and only if they are at least 1 day old (so we don't delete archives computed today that may be stil valid)
$query = " DELETE
FROM %s
WHERE period > ?
@@ -305,6 +319,8 @@ class Piwik_ArchiveProcessing_Period extends Piwik_ArchiveProcessing
Zend_Registry::get('db')->query(sprintf($query, $blobTable), Piwik::$idPeriods['day']);
Zend_Registry::get('db')->query(sprintf($query, $numericTable), Piwik::$idPeriods['day']);
+
+ Piwik_SetOption($key, time());
}
}