From eb06aca951cee6b01ceecf57286a892c77348d81 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 1 Feb 2018 11:28:06 -0800 Subject: [PATCH] Support DestructionEngine in MetaMTAMail Summary: Depends on D18984. Ref T13053. See D13408 for the original change and why this doesn't use DestructionEngine right now. The quick version is: - It causes us to write a destruction log, which is slightly silly (we're deleting one thing and creating another). - It's a little bit slower than not using DestructionEngine. However, it gets us some stuff for free that's likely relevant now (e.g., Herald Transcript cleanup) and I'm planning to move attachments to Files, but want to be able to delete them when mail is destroyed. The destruction log is a touch silly, but those records are very small and that log gets GC'd later without generating new logs. We could silence the log from the GC if it's ever an issue. Test Plan: Used `bin/remove destroy` and `bin/garbage collect --collector mail.sent` to destroy mail and collect garbage. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13053 Differential Revision: https://secure.phabricator.com/D18985 --- src/__phutil_library_map__.php | 1 + .../MetaMTAMailSentGarbageCollector.php | 3 ++- .../storage/PhabricatorMetaMTAMail.php | 26 ++++++++----------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f0e2d29cfc..aff0d5e36f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -8739,6 +8739,7 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAMail' => array( 'PhabricatorMetaMTADAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'PhabricatorMetaMTAMailBody' => 'Phobject', 'PhabricatorMetaMTAMailBodyTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php b/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php index c9ca274436..dacd46d187 100644 --- a/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php +++ b/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php @@ -18,8 +18,9 @@ final class MetaMTAMailSentGarbageCollector 'dateCreated < %d LIMIT 100', $this->getGarbageEpoch()); + $engine = new PhabricatorDestructionEngine(); foreach ($mails as $mail) { - $mail->delete(); + $engine->destroyObject($mail); } return (count($mails) == 100); diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index a9736c1766..d5111529f3 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -5,7 +5,9 @@ */ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO - implements PhabricatorPolicyInterface { + implements + PhabricatorPolicyInterface, + PhabricatorDestructibleInterface { const RETRY_DELAY = 5; @@ -1041,20 +1043,6 @@ 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; - } - public function generateHeaders() { $headers = array(); @@ -1306,4 +1294,12 @@ final class PhabricatorMetaMTAMail } +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + $this->delete(); + } + }