From 189fb2660a905c7d683cc312af66ca2065bc51d5 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Wed, 24 Jun 2015 11:44:49 -0700 Subject: [PATCH] MetaMTA - make sure mail garbage collection also cleans up recipient edges Summary: Ref T5791. This edge table grows 2+X faster than the corresponding mail table depending on usage. Ergo, lets make sure to clean that up too in the delete code. Test Plan: careful thought Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T5791 Differential Revision: https://secure.phabricator.com/D13408 --- .../MetaMTAMailSentGarbageCollector.php | 15 +++++++-------- .../metamta/storage/PhabricatorMetaMTAMail.php | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php b/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php index b4d4b05b76..f6df18bef6 100644 --- a/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php +++ b/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php @@ -6,16 +6,15 @@ final class MetaMTAMailSentGarbageCollector public function collectGarbage() { $ttl = phutil_units('90 days in seconds'); - $table = new PhabricatorMetaMTAMail(); - $conn_w = $table->establishConnection('w'); + $mails = id(new PhabricatorMetaMTAMail())->loadAllWhere( + 'dateCreated < %d LIMIT 100', + PhabricatorTime::getNow()); - queryfx( - $conn_w, - 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', - $table->getTableName(), - time() - $ttl); + foreach ($mails as $mail) { + $mail->delete(); + } - return ($conn_w->getAffectedRows() == 100); + return (count($mails) == 100); } } diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index ad7c07ed8e..ee09fa730f 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -1038,6 +1038,20 @@ final class PhabricatorMetaMTAMail } } + public function delete() { + $this->openTransaction(); + queryfx( + $this->establishConnection('w'), + 'DELETE FROM %T WHERE src = %s AND type = %d', + PhabricatorEdgeConfig::TABLE_NAME_EDGE, + $this->getPHID(), + PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST); + $ret = parent::delete(); + $this->saveTransaction(); + + return $ret; + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */