Skip to content

Commit 8843634

Browse files
author
epriestley
committedFeb 3, 2014
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
1 parent 29b29c1 commit 8843634

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_metamta.metamta_mail
2+
ADD KEY `key_created` (dateCreated);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE {$NAMESPACE}_metamta.metamta_receivedmail
2+
ADD KEY `key_created` (dateCreated);

‎src/__phutil_library_map__.php

+4
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,8 @@
923923
'ManiphestTransactionSaveController' => 'applications/maniphest/controller/ManiphestTransactionSaveController.php',
924924
'ManiphestView' => 'applications/maniphest/view/ManiphestView.php',
925925
'MetaMTAConstants' => 'applications/metamta/constants/MetaMTAConstants.php',
926+
'MetaMTAMailReceivedGarbageCollector' => 'applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php',
927+
'MetaMTAMailSentGarbageCollector' => 'applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php',
926928
'MetaMTANotificationType' => 'applications/metamta/constants/MetaMTANotificationType.php',
927929
'MetaMTAReceivedMailStatus' => 'applications/metamta/constants/MetaMTAReceivedMailStatus.php',
928930
'NuanceCapabilitySourceDefaultEdit' => 'applications/nuance/capability/NuanceCapabilitySourceDefaultEdit.php',
@@ -3513,6 +3515,8 @@
35133515
'ManiphestTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
35143516
'ManiphestTransactionSaveController' => 'ManiphestController',
35153517
'ManiphestView' => 'AphrontView',
3518+
'MetaMTAMailReceivedGarbageCollector' => 'PhabricatorGarbageCollector',
3519+
'MetaMTAMailSentGarbageCollector' => 'PhabricatorGarbageCollector',
35163520
'MetaMTANotificationType' => 'MetaMTAConstants',
35173521
'MetaMTAReceivedMailStatus' => 'MetaMTAConstants',
35183522
'NuanceCapabilitySourceDefaultEdit' => 'PhabricatorPolicyCapability',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
final class MetaMTAMailReceivedGarbageCollector
4+
extends PhabricatorGarbageCollector {
5+
6+
public function collectGarbage() {
7+
$ttl = phutil_units('90 days in seconds');
8+
9+
$table = new PhabricatorMetaMTAReceivedMail();
10+
$conn_w = $table->establishConnection('w');
11+
12+
queryfx(
13+
$conn_w,
14+
'DELETE FROM %T WHERE dateCreated < %d LIMIT 100',
15+
$table->getTableName(),
16+
time() - $ttl);
17+
18+
return ($conn_w->getAffectedRows() == 100);
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
final class MetaMTAMailSentGarbageCollector
4+
extends PhabricatorGarbageCollector {
5+
6+
public function collectGarbage() {
7+
$ttl = phutil_units('90 days in seconds');
8+
9+
$table = new PhabricatorMetaMTAMail();
10+
$conn_w = $table->establishConnection('w');
11+
12+
queryfx(
13+
$conn_w,
14+
'DELETE FROM %T WHERE dateCreated < %d LIMIT 100',
15+
$table->getTableName(),
16+
time() - $ttl);
17+
18+
return ($conn_w->getAffectedRows() == 100);
19+
}
20+
21+
}

0 commit comments

Comments
 (0)
Failed to load comments.