diff --git a/resources/sql/autopatches/20140201.gc.1.mailsent.sql b/resources/sql/autopatches/20140201.gc.1.mailsent.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20140201.gc.1.mailsent.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_metamta.metamta_mail + ADD KEY `key_created` (dateCreated); diff --git a/resources/sql/autopatches/20140201.gc.2.mailreceived.sql b/resources/sql/autopatches/20140201.gc.2.mailreceived.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20140201.gc.2.mailreceived.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_metamta.metamta_receivedmail + ADD KEY `key_created` (dateCreated); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -923,6 +923,8 @@ '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 @@ 'ManiphestTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'ManiphestTransactionSaveController' => 'ManiphestController', 'ManiphestView' => 'AphrontView', + 'MetaMTAMailReceivedGarbageCollector' => 'PhabricatorGarbageCollector', + 'MetaMTAMailSentGarbageCollector' => 'PhabricatorGarbageCollector', 'MetaMTANotificationType' => 'MetaMTAConstants', 'MetaMTAReceivedMailStatus' => 'MetaMTAConstants', 'NuanceCapabilitySourceDefaultEdit' => 'PhabricatorPolicyCapability', diff --git a/src/applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php b/src/applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php new file mode 100644 --- /dev/null +++ b/src/applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php @@ -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); + } + +} diff --git a/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php b/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php new file mode 100644 --- /dev/null +++ b/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php @@ -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); + } + +}