From 4be568d34611ced7766605a57b568cfe82958170 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Mon, 22 Jun 2015 14:14:21 -0700 Subject: [PATCH] MetaMTA - save actorPHID as its own column Summary: Ref T5791. This should make performance snappy wrt policy checks in some future diff where the Query is updated and in use somewhere in the application. Test Plan: ran `./bin/storage upgrade`. commented on a task and saw actorPHID populated correctly in underlying MetaMTAMail object database entry Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T5791 Differential Revision: https://secure.phabricator.com/D13396 --- .../20150622.metamta.4.actor-phid-col.sql | 2 ++ .../20150622.metamta.5.actor-phid-mig.php | 27 +++++++++++++++++++ .../20150622.metamta.6.actor-phid-key.sql | 2 ++ .../storage/PhabricatorMetaMTAMail.php | 10 +++++++ 4 files changed, 41 insertions(+) create mode 100644 resources/sql/autopatches/20150622.metamta.4.actor-phid-col.sql create mode 100644 resources/sql/autopatches/20150622.metamta.5.actor-phid-mig.php create mode 100644 resources/sql/autopatches/20150622.metamta.6.actor-phid-key.sql diff --git a/resources/sql/autopatches/20150622.metamta.4.actor-phid-col.sql b/resources/sql/autopatches/20150622.metamta.4.actor-phid-col.sql new file mode 100644 index 0000000000..cc0bcb221a --- /dev/null +++ b/resources/sql/autopatches/20150622.metamta.4.actor-phid-col.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_metamta.metamta_mail + ADD actorPHID VARBINARY(64) AFTER phid; diff --git a/resources/sql/autopatches/20150622.metamta.5.actor-phid-mig.php b/resources/sql/autopatches/20150622.metamta.5.actor-phid-mig.php new file mode 100644 index 0000000000..d27e54098f --- /dev/null +++ b/resources/sql/autopatches/20150622.metamta.5.actor-phid-mig.php @@ -0,0 +1,27 @@ +establishConnection('w'); + +echo pht('Assigning actorPHIDs to mails...')."\n"; +foreach (new LiskMigrationIterator($table) as $mail) { + $id = $mail->getID(); + + echo pht('Updating mail %d...', $id)."\n"; + if ($mail->getActorPHID()) { + continue; + } + + $actor_phid = $mail->getFrom(); + if ($actor_phid === null) { + continue; + } + + queryfx( + $conn_w, + 'UPDATE %T SET actorPHID = %s WHERE id = %d', + $table->getTableName(), + $actor_phid, + $id); +} +echo pht('Done.')."\n"; diff --git a/resources/sql/autopatches/20150622.metamta.6.actor-phid-key.sql b/resources/sql/autopatches/20150622.metamta.6.actor-phid-key.sql new file mode 100644 index 0000000000..7b0bb0e867 --- /dev/null +++ b/resources/sql/autopatches/20150622.metamta.6.actor-phid-key.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_metamta.metamta_mail + ADD KEY `key_actorPHID` (actorPHID); diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index 61f376381a..d232f17cb4 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -14,6 +14,7 @@ final class PhabricatorMetaMTAMail const RETRY_DELAY = 5; + protected $actorPHID; protected $parameters; protected $status; protected $message; @@ -36,6 +37,7 @@ final class PhabricatorMetaMTAMail 'parameters' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( + 'actorPHID' => 'phid?', 'status' => 'text32', 'relatedPHID' => 'phid?', @@ -47,6 +49,9 @@ final class PhabricatorMetaMTAMail 'status' => array( 'columns' => array('status'), ), + 'key_actorPHID' => array( + 'columns' => array('actorPHID'), + ), 'relatedPHID' => array( 'columns' => array('relatedPHID'), ), @@ -219,9 +224,14 @@ final class PhabricatorMetaMTAMail public function setFrom($from) { $this->setParam('from', $from); + $this->setActorPHID($from); return $this; } + public function getFrom() { + return $this->getParam('from'); + } + public function setRawFrom($raw_email, $raw_name) { $this->setParam('raw-from', array($raw_email, $raw_name)); return $this;