1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 08:20:57 +01:00

Add a GC for sent and received mail

Summary: Ref T4368. We don't currently GC these tables, and the sent mail table is one of the largest on `secure.phabricator.com`. There's no value in retaining this information indefinitely. Instead, retain it for 90 days, which should be plenty of time to debug/diagnose any issues.

Test Plan: Ran `phd debug garbage`, saw it clean up a reasonable amount of data from these tables.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4368

Differential Revision: https://secure.phabricator.com/D8127
This commit is contained in:
epriestley 2014-02-03 10:51:31 -08:00
parent 29b29c109d
commit 88436349b8
5 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_metamta.metamta_mail
ADD KEY `key_created` (dateCreated);

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_metamta.metamta_receivedmail
ADD KEY `key_created` (dateCreated);

View file

@ -923,6 +923,8 @@ phutil_register_library_map(array(
'ManiphestTransactionSaveController' => 'applications/maniphest/controller/ManiphestTransactionSaveController.php',
'ManiphestView' => 'applications/maniphest/view/ManiphestView.php',
'MetaMTAConstants' => 'applications/metamta/constants/MetaMTAConstants.php',
'MetaMTAMailReceivedGarbageCollector' => 'applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php',
'MetaMTAMailSentGarbageCollector' => 'applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php',
'MetaMTANotificationType' => 'applications/metamta/constants/MetaMTANotificationType.php',
'MetaMTAReceivedMailStatus' => 'applications/metamta/constants/MetaMTAReceivedMailStatus.php',
'NuanceCapabilitySourceDefaultEdit' => 'applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php',
@ -3513,6 +3515,8 @@ phutil_register_library_map(array(
'ManiphestTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'ManiphestTransactionSaveController' => 'ManiphestController',
'ManiphestView' => 'AphrontView',
'MetaMTAMailReceivedGarbageCollector' => 'PhabricatorGarbageCollector',
'MetaMTAMailSentGarbageCollector' => 'PhabricatorGarbageCollector',
'MetaMTANotificationType' => 'MetaMTAConstants',
'MetaMTAReceivedMailStatus' => 'MetaMTAConstants',
'NuanceCapabilitySourceDefaultEdit' => 'PhabricatorPolicyCapability',

View file

@ -0,0 +1,21 @@
<?php
final class MetaMTAMailReceivedGarbageCollector
extends PhabricatorGarbageCollector {
public function collectGarbage() {
$ttl = phutil_units('90 days in seconds');
$table = new PhabricatorMetaMTAReceivedMail();
$conn_w = $table->establishConnection('w');
queryfx(
$conn_w,
'DELETE FROM %T WHERE dateCreated < %d LIMIT 100',
$table->getTableName(),
time() - $ttl);
return ($conn_w->getAffectedRows() == 100);
}
}

View file

@ -0,0 +1,21 @@
<?php
final class MetaMTAMailSentGarbageCollector
extends PhabricatorGarbageCollector {
public function collectGarbage() {
$ttl = phutil_units('90 days in seconds');
$table = new PhabricatorMetaMTAMail();
$conn_w = $table->establishConnection('w');
queryfx(
$conn_w,
'DELETE FROM %T WHERE dateCreated < %d LIMIT 100',
$table->getTableName(),
time() - $ttl);
return ($conn_w->getAffectedRows() == 100);
}
}