diff --git a/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php b/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php --- a/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php +++ b/src/applications/metamta/garbagecollector/MetaMTAMailSentGarbageCollector.php @@ -6,16 +6,15 @@ 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 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -1038,6 +1038,20 @@ } } + 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 )----------------------------------------- */