@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove "dateTouched" from ConpherenceParticipant

Summary:
Pathway to D17685. This column is (mostly) a denormalization of `dateModified` on the thread.

Just use a JOIN instead.

This isn't //exactly// the same: we'll bump threads to the top now for non-message changes (e.g., a topic or title change). That seems fine, but we could put a `lastMessageDate` on Thread later if we want to refine it.

Also got rid of a lot of other unused stuff. There's a big garbage TODO here, I'll fix that in the next change.

Test Plan:
- Grepped for `dateTouched`.
- Grepped for `participantCursor`.
- Grepped for `ConpherenceParticipantQuery::LIMIT`.
- Looked for callsites to `setOrder()`, found none.
- Added a message to an older thread, saw it bump up to the top.

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D17731

+30 -100
+2
resources/sql/autopatches/20170419.thread.03.touched.sql
··· 1 + ALTER TABLE {$NAMESPACE}_conpherence.conpherence_participant 2 + DROP dateTouched;
-4
src/applications/conpherence/editor/ConpherenceEditor.php
··· 181 181 id(new ConpherenceParticipant()) 182 182 ->setConpherencePHID($object->getPHID()) 183 183 ->setParticipantPHID($phid) 184 - ->setDateTouched(time()) 185 184 ->setSeenMessageCount($message_count) 186 185 ->save(); 187 186 $object->attachParticipants($participants); ··· 248 247 id(new ConpherenceParticipant()) 249 248 ->setConpherencePHID($object->getPHID()) 250 249 ->setParticipantPHID($phid) 251 - ->setDateTouched(time()) 252 250 ->setSeenMessageCount($message_count) 253 251 ->save(); 254 252 } ··· 282 280 $participant->setSeenMessageCount( 283 281 $object->getMessageCount() - $message_count); 284 282 } 285 - $participant->setDateTouched($time); 286 283 } else { 287 284 $participant->setSeenMessageCount($object->getMessageCount()); 288 - $participant->setDateTouched($time); 289 285 } 290 286 $participant->save(); 291 287 }
+28 -91
src/applications/conpherence/query/ConpherenceParticipantQuery.php
··· 1 1 <?php 2 2 3 - /** 4 - * Query class that answers these questions: 5 - * 6 - * - Q: What are the conpherences to show when I land on /conpherence/ ? 7 - * - A: 8 - * 9 - * id(new ConpherenceParticipantQuery()) 10 - * ->withParticipantPHIDs(array($my_phid)) 11 - * ->execute(); 12 - * 13 - * - Q: What are the next set of conpherences as I scroll up (more recent) or 14 - * down (less recent) this list of conpherences? 15 - * - A: 16 - * 17 - * id(new ConpherenceParticipantQuery()) 18 - * ->withParticipantPHIDs(array($my_phid)) 19 - * ->withParticipantCursor($top_participant) 20 - * ->setOrder(ConpherenceParticipantQuery::ORDER_NEWER) 21 - * ->execute(); 22 - * 23 - * -or- 24 - * 25 - * id(new ConpherenceParticipantQuery()) 26 - * ->withParticipantPHIDs(array($my_phid)) 27 - * ->withParticipantCursor($bottom_participant) 28 - * ->setOrder(ConpherenceParticipantQuery::ORDER_OLDER) 29 - * ->execute(); 30 - * 31 - * For counts of read, un-read, or all conpherences by participant, see 32 - * @{class:ConpherenceParticipantCountQuery}. 33 - */ 34 3 final class ConpherenceParticipantQuery extends PhabricatorOffsetPagedQuery { 35 4 36 - const LIMIT = 100; 37 - const ORDER_NEWER = 'newer'; 38 - const ORDER_OLDER = 'older'; 39 - 40 5 private $participantPHIDs; 41 - private $participantCursor; 42 - private $order = self::ORDER_OLDER; 43 6 44 7 public function withParticipantPHIDs(array $phids) { 45 8 $this->participantPHIDs = $phids; 46 9 return $this; 47 10 } 48 11 49 - public function withParticipantCursor(ConpherenceParticipant $participant) { 50 - $this->participantCursor = $participant; 51 - return $this; 52 - } 53 - 54 - public function setOrder($order) { 55 - $this->order = $order; 56 - return $this; 57 - } 58 - 59 12 public function execute() { 60 13 $table = new ConpherenceParticipant(); 61 - $conn_r = $table->establishConnection('r'); 14 + $thread = new ConpherenceThread(); 15 + 16 + $conn = $table->establishConnection('r'); 62 17 63 18 $data = queryfx_all( 64 - $conn_r, 65 - 'SELECT * FROM %T participant %Q %Q %Q', 19 + $conn, 20 + 'SELECT * FROM %T participant JOIN %T thread 21 + ON participant.conpherencePHID = thread.phid %Q %Q %Q', 66 22 $table->getTableName(), 67 - $this->buildWhereClause($conn_r), 68 - $this->buildOrderClause($conn_r), 69 - $this->buildLimitClause($conn_r)); 23 + $thread->getTableName(), 24 + $this->buildWhereClause($conn), 25 + $this->buildOrderClause($conn), 26 + $this->buildLimitClause($conn)); 70 27 71 28 $participants = $table->loadAllFromArray($data); 72 29 73 - $participants = mpull($participants, null, 'getConpherencePHID'); 74 - 75 - if ($this->order == self::ORDER_NEWER) { 76 - $participants = array_reverse($participants); 30 + // TODO: Fix this, it's bogus. 31 + if ('garbage') { 32 + if (count($this->participantPHIDs) !== 1) { 33 + throw new Exception( 34 + pht( 35 + 'This query only works when querying for exactly one participant '. 36 + 'PHID!')); 37 + } 38 + // This will throw results away if we aren't doing a query for exactly 39 + // one participant PHID. 40 + $participants = mpull($participants, null, 'getConpherencePHID'); 77 41 } 78 42 79 43 return $participants; 80 44 } 81 45 82 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 46 + protected function buildWhereClause(AphrontDatabaseConnection $conn) { 83 47 $where = array(); 84 48 85 - if ($this->participantPHIDs) { 49 + if ($this->participantPHIDs !== null) { 86 50 $where[] = qsprintf( 87 - $conn_r, 51 + $conn, 88 52 'participantPHID IN (%Ls)', 89 53 $this->participantPHIDs); 90 54 } 91 55 92 - if ($this->participantCursor) { 93 - $date_touched = $this->participantCursor->getDateTouched(); 94 - $id = $this->participantCursor->getID(); 95 - if ($this->order == self::ORDER_OLDER) { 96 - $compare_date = '<'; 97 - $compare_id = '<='; 98 - } else { 99 - $compare_date = '>'; 100 - $compare_id = '>='; 101 - } 102 - $where[] = qsprintf( 103 - $conn_r, 104 - '(dateTouched %Q %d OR (dateTouched = %d AND id %Q %d))', 105 - $compare_date, 106 - $date_touched, 107 - $date_touched, 108 - $compare_id, 109 - $id); 110 - } 111 - 112 56 return $this->formatWhereClause($where); 113 57 } 114 58 115 - private function buildOrderClause(AphrontDatabaseConnection $conn_r) { 116 - $order_word = ($this->order == self::ORDER_OLDER) ? 'DESC' : 'ASC'; 117 - // if these are different direction we won't get as efficient a query 118 - // see http://dev.mysql.com/doc/refman/5.5/en/order-by-optimization.html 119 - $order = qsprintf( 120 - $conn_r, 121 - 'ORDER BY dateTouched %Q, id %Q', 122 - $order_word, 123 - $order_word); 124 - 125 - return $order; 59 + private function buildOrderClause(AphrontDatabaseConnection $conn) { 60 + return qsprintf( 61 + $conn, 62 + 'ORDER BY thread.dateModified DESC, thread.id DESC, participant.id DESC'); 126 63 } 127 64 128 65 }
-5
src/applications/conpherence/storage/ConpherenceParticipant.php
··· 5 5 protected $participantPHID; 6 6 protected $conpherencePHID; 7 7 protected $seenMessageCount; 8 - protected $dateTouched; 9 8 protected $settings = array(); 10 9 11 10 protected function getConfiguration() { ··· 14 13 'settings' => self::SERIALIZATION_JSON, 15 14 ), 16 15 self::CONFIG_COLUMN_SCHEMA => array( 17 - 'dateTouched' => 'epoch', 18 16 'seenMessageCount' => 'uint64', 19 17 ), 20 18 self::CONFIG_KEY_SCHEMA => array( 21 19 'conpherencePHID' => array( 22 20 'columns' => array('conpherencePHID', 'participantPHID'), 23 21 'unique' => true, 24 - ), 25 - 'participationIndex' => array( 26 - 'columns' => array('participantPHID', 'dateTouched', 'id'), 27 22 ), 28 23 'key_thread' => array( 29 24 'columns' => array('participantPHID', 'conpherencePHID'),