@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

Remove "participationStatus" from ConpherenceParticipant

Summary:
Pathway to D17685. This column is a very complicated cache of: is participant.messageCount equal to thread.messageCount?

We can just ask this question with a JOIN instead and simplify things dramatically.

Test Plan:
- Ran migration.
- Browsed around.
- Sent a message, saw unread count go up.
- Read the message, saw unread count go down.

Reviewers: chad

Reviewed By: chad

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

+41 -71
+2
resources/sql/autopatches/20170419.thread.02.status.sql
··· 1 + ALTER TABLE {$NAMESPACE}_conpherence.conpherence_participant 2 + DROP participationStatus;
-2
src/__phutil_library_map__.php
··· 305 305 'ConpherenceParticipantCountQuery' => 'applications/conpherence/query/ConpherenceParticipantCountQuery.php', 306 306 'ConpherenceParticipantQuery' => 'applications/conpherence/query/ConpherenceParticipantQuery.php', 307 307 'ConpherenceParticipantView' => 'applications/conpherence/view/ConpherenceParticipantView.php', 308 - 'ConpherenceParticipationStatus' => 'applications/conpherence/constants/ConpherenceParticipationStatus.php', 309 308 'ConpherenceQueryThreadConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceQueryThreadConduitAPIMethod.php', 310 309 'ConpherenceQueryTransactionConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceQueryTransactionConduitAPIMethod.php', 311 310 'ConpherenceReplyHandler' => 'applications/conpherence/mail/ConpherenceReplyHandler.php', ··· 5099 5098 'ConpherenceParticipantCountQuery' => 'PhabricatorOffsetPagedQuery', 5100 5099 'ConpherenceParticipantQuery' => 'PhabricatorOffsetPagedQuery', 5101 5100 'ConpherenceParticipantView' => 'AphrontView', 5102 - 'ConpherenceParticipationStatus' => 'ConpherenceConstants', 5103 5101 'ConpherenceQueryThreadConduitAPIMethod' => 'ConpherenceConduitAPIMethod', 5104 5102 'ConpherenceQueryTransactionConduitAPIMethod' => 'ConpherenceConduitAPIMethod', 5105 5103 'ConpherenceReplyHandler' => 'PhabricatorMailReplyHandler',
-8
src/applications/conpherence/constants/ConpherenceParticipationStatus.php
··· 1 - <?php 2 - 3 - final class ConpherenceParticipationStatus extends ConpherenceConstants { 4 - 5 - const UP_TO_DATE = 0; 6 - const BEHIND = 1; 7 - 8 - }
+2 -3
src/applications/conpherence/controller/ConpherenceNotificationPanelController.php
··· 7 7 $user = $request->getUser(); 8 8 $conpherences = array(); 9 9 require_celerity_resource('conpherence-notification-css'); 10 - $unread_status = ConpherenceParticipationStatus::BEHIND; 11 10 12 11 $participant_data = id(new ConpherenceParticipantQuery()) 13 12 ->withParticipantPHIDs(array($user->getPHID())) ··· 37 36 'conpherence-notification', 38 37 ); 39 38 40 - if ($p_data->getParticipationStatus() == $unread_status) { 39 + if (!$p_data->isUpToDate($conpherence)) { 41 40 $classes[] = 'phabricator-notification-unread'; 42 41 } 43 42 $uri = $this->getApplicationURI($conpherence->getID().'/'); ··· 95 94 96 95 $unread = id(new ConpherenceParticipantCountQuery()) 97 96 ->withParticipantPHIDs(array($user->getPHID())) 98 - ->withParticipationStatus($unread_status) 97 + ->withUnread(true) 99 98 ->execute(); 100 99 $unread_count = idx($unread, $user->getPHID(), 0); 101 100
+1 -11
src/applications/conpherence/editor/ConpherenceEditor.php
··· 173 173 $phids = $this->getPHIDTransactionNewValue($xaction, array()); 174 174 foreach ($phids as $phid) { 175 175 if ($phid == $this->getActor()->getPHID()) { 176 - $status = ConpherenceParticipationStatus::UP_TO_DATE; 177 176 $message_count = 1; 178 177 } else { 179 - $status = ConpherenceParticipationStatus::BEHIND; 180 178 $message_count = 0; 181 179 } 182 180 $participants[$phid] = 183 181 id(new ConpherenceParticipant()) 184 182 ->setConpherencePHID($object->getPHID()) 185 183 ->setParticipantPHID($phid) 186 - ->setParticipationStatus($status) 187 184 ->setDateTouched(time()) 188 185 ->setSeenMessageCount($message_count) 189 186 ->save(); ··· 243 240 $add = array_keys(array_diff_key($new_map, $old_map)); 244 241 foreach ($add as $phid) { 245 242 if ($phid == $this->getActor()->getPHID()) { 246 - $status = ConpherenceParticipationStatus::UP_TO_DATE; 247 243 $message_count = $object->getMessageCount(); 248 244 } else { 249 - $status = ConpherenceParticipationStatus::BEHIND; 250 245 $message_count = 0; 251 246 } 252 247 $participants[$phid] = 253 248 id(new ConpherenceParticipant()) 254 249 ->setConpherencePHID($object->getPHID()) 255 250 ->setParticipantPHID($phid) 256 - ->setParticipationStatus($status) 257 251 ->setDateTouched(time()) 258 252 ->setSeenMessageCount($message_count) 259 253 ->save(); ··· 279 273 280 274 // update everyone's participation status on a message -only- 281 275 $xaction_phid = $xaction->getPHID(); 282 - $behind = ConpherenceParticipationStatus::BEHIND; 283 - $up_to_date = ConpherenceParticipationStatus::UP_TO_DATE; 284 276 $participants = $object->getParticipants(); 285 277 $user = $this->getActor(); 286 278 $time = time(); 287 279 foreach ($participants as $phid => $participant) { 288 280 if ($phid != $user->getPHID()) { 289 - if ($participant->getParticipationStatus() != $behind) { 281 + if ($participant->isUpToDate($object)) { 290 282 $participant->setSeenMessageCount( 291 283 $object->getMessageCount() - $message_count); 292 284 } 293 - $participant->setParticipationStatus($behind); 294 285 $participant->setDateTouched($time); 295 286 } else { 296 287 $participant->setSeenMessageCount($object->getMessageCount()); 297 - $participant->setParticipationStatus($up_to_date); 298 288 $participant->setDateTouched($time); 299 289 } 300 290 $participant->save();
+30 -34
src/applications/conpherence/query/ConpherenceParticipantCountQuery.php
··· 1 1 <?php 2 2 3 - /** 4 - * Query class that answers the question: 5 - * 6 - * - Q: How many unread conpherences am I participating in? 7 - * - A: 8 - * id(new ConpherenceParticipantCountQuery()) 9 - * ->withParticipantPHIDs(array($my_phid)) 10 - * ->withParticipationStatus(ConpherenceParticipationStatus::BEHIND) 11 - * ->execute(); 12 - */ 13 3 final class ConpherenceParticipantCountQuery 14 4 extends PhabricatorOffsetPagedQuery { 15 5 16 6 private $participantPHIDs; 17 - private $participationStatus; 7 + private $unread; 18 8 19 9 public function withParticipantPHIDs(array $phids) { 20 10 $this->participantPHIDs = $phids; 21 11 return $this; 22 12 } 23 13 24 - public function withParticipationStatus($participation_status) { 25 - $this->participationStatus = $participation_status; 14 + public function withUnread($unread) { 15 + $this->unread = $unread; 26 16 return $this; 27 17 } 28 18 29 19 public function execute() { 20 + $thread = new ConpherenceThread(); 30 21 $table = new ConpherenceParticipant(); 31 - $conn_r = $table->establishConnection('r'); 22 + $conn = $table->establishConnection('r'); 32 23 33 24 $rows = queryfx_all( 34 - $conn_r, 35 - 'SELECT COUNT(*) as count, participantPHID '. 36 - 'FROM %T participant %Q %Q %Q', 25 + $conn, 26 + 'SELECT COUNT(*) as count, participantPHID 27 + FROM %T participant JOIN %T thread 28 + ON participant.conpherencePHID = thread.phid %Q %Q %Q', 37 29 $table->getTableName(), 38 - $this->buildWhereClause($conn_r), 39 - $this->buildGroupByClause($conn_r), 40 - $this->buildLimitClause($conn_r)); 30 + $thread->getTableName(), 31 + $this->buildWhereClause($conn), 32 + $this->buildGroupByClause($conn), 33 + $this->buildLimitClause($conn)); 41 34 42 35 return ipull($rows, 'count', 'participantPHID'); 43 36 } 44 37 45 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 38 + protected function buildWhereClause(AphrontDatabaseConnection $conn) { 46 39 $where = array(); 47 40 48 - if ($this->participantPHIDs) { 41 + if ($this->participantPHIDs !== null) { 49 42 $where[] = qsprintf( 50 - $conn_r, 51 - 'participantPHID IN (%Ls)', 43 + $conn, 44 + 'participant.participantPHID IN (%Ls)', 52 45 $this->participantPHIDs); 53 46 } 54 47 55 - if ($this->participationStatus !== null) { 56 - $where[] = qsprintf( 57 - $conn_r, 58 - 'participationStatus = %d', 59 - $this->participationStatus); 48 + if ($this->unread !== null) { 49 + if ($this->unread) { 50 + $where[] = qsprintf( 51 + $conn, 52 + 'participant.seenMessageCount < thread.messageCount'); 53 + } else { 54 + $where[] = qsprintf( 55 + $conn, 56 + 'participant.seenMessageCount >= thread.messageCount'); 57 + } 60 58 } 61 59 62 60 return $this->formatWhereClause($where); 63 61 } 64 62 65 - private function buildGroupByClause(AphrontDatabaseConnection $conn_r) { 66 - $group_by = qsprintf( 67 - $conn_r, 63 + private function buildGroupByClause(AphrontDatabaseConnection $conn) { 64 + return qsprintf( 65 + $conn, 68 66 'GROUP BY participantPHID'); 69 - 70 - return $group_by; 71 67 } 72 68 73 69 }
+5 -11
src/applications/conpherence/storage/ConpherenceParticipant.php
··· 4 4 5 5 protected $participantPHID; 6 6 protected $conpherencePHID; 7 - protected $participationStatus; 8 7 protected $seenMessageCount; 9 8 protected $dateTouched; 10 9 protected $settings = array(); ··· 15 14 'settings' => self::SERIALIZATION_JSON, 16 15 ), 17 16 self::CONFIG_COLUMN_SCHEMA => array( 18 - 'participationStatus' => 'uint32', 19 17 'dateTouched' => 'epoch', 20 18 'seenMessageCount' => 'uint64', 21 19 ), ··· 24 22 'columns' => array('conpherencePHID', 'participantPHID'), 25 23 'unique' => true, 26 24 ), 27 - 'unreadCount' => array( 28 - 'columns' => array('participantPHID', 'participationStatus'), 29 - ), 30 25 'participationIndex' => array( 31 26 'columns' => array('participantPHID', 'dateTouched', 'id'), 27 + ), 28 + 'key_thread' => array( 29 + 'columns' => array('participantPHID', 'conpherencePHID'), 32 30 ), 33 31 ), 34 32 ) + parent::getConfiguration(); ··· 41 39 public function markUpToDate( 42 40 ConpherenceThread $conpherence, 43 41 ConpherenceTransaction $xaction) { 42 + 44 43 if (!$this->isUpToDate($conpherence)) { 45 - $this->setParticipationStatus(ConpherenceParticipationStatus::UP_TO_DATE); 46 44 $this->setSeenMessageCount($conpherence->getMessageCount()); 47 45 $this->save(); 48 46 ··· 55 53 } 56 54 57 55 public function isUpToDate(ConpherenceThread $conpherence) { 58 - return 59 - ($this->getSeenMessageCount() == $conpherence->getMessageCount()) 60 - && 61 - ($this->getParticipationStatus() == 62 - ConpherenceParticipationStatus::UP_TO_DATE); 56 + return ($this->getSeenMessageCount() == $conpherence->getMessageCount()); 63 57 } 64 58 65 59 }
+1 -2
src/applications/people/cache/PhabricatorUserMessageCountCacheType.php
··· 28 28 29 29 $user_phids = mpull($users, 'getPHID'); 30 30 31 - $unread_status = ConpherenceParticipationStatus::BEHIND; 32 31 $unread = id(new ConpherenceParticipantCountQuery()) 33 32 ->withParticipantPHIDs($user_phids) 34 - ->withParticipationStatus($unread_status) 33 + ->withUnread(true) 35 34 ->execute(); 36 35 37 36 $empty = array_fill_keys($user_phids, 0);