@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.

Conpherence - get back-end prepped for loading less transactions all the time

Summary: this just does the back-end migration. I realized that we don't need to keep track of cacheTitle and cachePhoto since those are based off recent participation handles and dynamic relative to who is viewing it. Also kept the "last seen phid" as I think that will be useful to have auto-scroll to where you last read. Ref T2867.

Test Plan: did the migration. observed sensical values in the database. created a new conpherence - again sensical values. updated a conpherence - more sensical values.

Reviewers: epriestley, chad

Reviewed By: epriestley

CC: aran, Korvin, AnhNhan

Maniphest Tasks: T2867

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

+132 -6
+6
resources/sql/patches/20130403.conpherencecache.sql
··· 1 + ALTER TABLE {$NAMESPACE}_conpherence.conpherence_thread 2 + ADD recentParticipantPHIDs LONGTEXT NOT NULL COLLATE utf8_bin AFTER title, 3 + ADD messageCount BIGINT UNSIGNED NOT NULL AFTER title; 4 + 5 + ALTER TABLE {$NAMESPACE}_conpherence.conpherence_participant 6 + ADD seenMessageCount BIGINT UNSIGNED NOT NULL AFTER behindTransactionPHID;
+64
resources/sql/patches/20130403.conpherencecachemig.php
··· 1 + <?php 2 + 3 + echo "Migrating data from conpherence transactions to conpherence 'cache'...\n"; 4 + 5 + $table = new ConpherenceThread(); 6 + $table->openTransaction(); 7 + $conn_w = $table->establishConnection('w'); 8 + 9 + $participant_table = new ConpherenceParticipant(); 10 + 11 + $conpherences = new LiskMigrationIterator($table); 12 + foreach ($conpherences as $conpherence) { 13 + echo 'Migrating conpherence #'.$conpherence->getID()."\n"; 14 + 15 + $participants = id(new ConpherenceParticipant()) 16 + ->loadAllWhere('conpherencePHID = %s', $conpherence->getPHID()); 17 + 18 + $transactions = id(new ConpherenceTransaction()) 19 + ->loadAllWhere('objectPHID = %s', $conpherence->getPHID()); 20 + 21 + $participation_hash = mgroup($participants, 'getBehindTransactionPHID'); 22 + 23 + $message_count = 0; 24 + $participants_to_cache = array(); 25 + foreach ($transactions as $transaction) { 26 + $participants_to_cache[] = $transaction->getAuthorPHID(); 27 + if ($transaction->getTransactionType() == 28 + PhabricatorTransactions::TYPE_COMMENT) { 29 + $message_count++; 30 + } 31 + $participants_to_update = idx( 32 + $participation_hash, 33 + $transaction->getPHID(), 34 + array()); 35 + if ($participants_to_update) { 36 + queryfx( 37 + $conn_w, 38 + 'UPDATE %T SET seenMessageCount = %d '. 39 + 'WHERE conpherencePHID = %s AND participantPHID IN (%Ls)', 40 + $participant_table->getTableName(), 41 + $message_count, 42 + $conpherence->getPHID(), 43 + mpull($participants_to_update, 'getParticipantPHID')); 44 + } 45 + } 46 + 47 + $participants_to_cache = array_slice( 48 + array_unique(array_reverse($participants_to_cache)), 49 + 0, 50 + 10); 51 + queryfx( 52 + $conn_w, 53 + 'UPDATE %T '. 54 + 'SET recentParticipantPHIDs = %s, '. 55 + 'messageCount = %d '. 56 + 'WHERE phid = %s', 57 + $table->getTableName(), 58 + json_encode($participants_to_cache), 59 + $message_count, 60 + $conpherence->getPHID()); 61 + } 62 + 63 + $table->saveTransaction(); 64 + echo "\nDone.\n";
+4 -1
src/applications/conpherence/controller/ConpherenceNewController.php
··· 11 11 12 12 $conpherence = id(new ConpherenceThread()) 13 13 ->attachParticipants(array()) 14 - ->attachFilePHIDs(array()); 14 + ->attachFilePHIDs(array()) 15 + ->setMessageCount(0); 15 16 $title = pht('New Conversation'); 16 17 $participants = array(); 17 18 $message = ''; ··· 34 35 } else { 35 36 $participants[] = $user->getPHID(); 36 37 $participants = array_unique($participants); 38 + $conpherence->setRecentParticipantPHIDs( 39 + array_slice($participants, 0, 10)); 37 40 } 38 41 39 42 $message = $request->getStr('message');
+1 -1
src/applications/conpherence/controller/ConpherenceViewController.php
··· 49 49 $transactions = $conpherence->getTransactions(); 50 50 $latest_transaction = end($transactions); 51 51 $write_guard = AphrontWriteGuard::beginScopedUnguardedWrites(); 52 - $participant->markUpToDate($latest_transaction); 52 + $participant->markUpToDate($conpherence, $latest_transaction); 53 53 unset($write_guard); 54 54 55 55 $header = $this->renderHeaderPaneContent();
+40 -1
src/applications/conpherence/editor/ConpherenceEditor.php
··· 86 86 } 87 87 } 88 88 89 + /** 90 + * We really only need a read lock if we have a comment. In that case, we 91 + * must update the messagesCount field on the conpherence and 92 + * seenMessagesCount(s) for the participant(s). 93 + */ 94 + protected function shouldReadLock( 95 + PhabricatorLiskDAO $object, 96 + PhabricatorApplicationTransaction $xaction) { 97 + 98 + $lock = false; 99 + switch ($xaction->getTransactionType()) { 100 + case PhabricatorTransactions::TYPE_COMMENT: 101 + $lock = true; 102 + break; 103 + } 104 + 105 + return $lock; 106 + } 107 + 89 108 protected function applyCustomInternalTransaction( 90 109 PhabricatorLiskDAO $object, 91 110 PhabricatorApplicationTransaction $xaction) { 92 - 93 111 switch ($xaction->getTransactionType()) { 112 + case PhabricatorTransactions::TYPE_COMMENT: 113 + $object->setMessageCount((int)$object->getMessageCount() + 1); 114 + break; 94 115 case ConpherenceTransactionType::TYPE_TITLE: 95 116 $object->setTitle($xaction->getNewValue()); 96 117 break; ··· 105 126 ConpherenceImageData::SIZE_HEAD); 106 127 break; 107 128 } 129 + $this->updateRecentParticipantPHIDs($object, $xaction); 130 + } 131 + 132 + private function updateRecentParticipantPHIDs( 133 + PhabricatorLiskDAO $object, 134 + PhabricatorApplicationTransaction $xaction) { 135 + 136 + $participants = $object->getRecentParticipantPHIDs(); 137 + array_unshift($participants, $xaction->getAuthorPHID()); 138 + $participants = array_slice(array_unique($participants), 0, 10); 139 + 140 + $object->setRecentParticipantPHIDs($participants); 108 141 } 109 142 110 143 /** ··· 148 181 if ($phid != $user->getPHID()) { 149 182 if ($participant->getParticipationStatus() != $behind) { 150 183 $participant->setBehindTransactionPHID($xaction_phid); 184 + // decrement one as this is the message putting them behind! 185 + $participant->setSeenMessageCount($object->getMessageCount() - 1); 151 186 } 152 187 $participant->setParticipationStatus($behind); 153 188 $participant->setDateTouched($time); 154 189 } else { 190 + $participant->setSeenMessageCount($object->getMessageCount()); 155 191 $participant->setParticipationStatus($up_to_date); 156 192 $participant->setDateTouched($time); 157 193 } ··· 176 212 foreach ($add as $phid) { 177 213 if ($phid == $this->getActor()->getPHID()) { 178 214 $status = ConpherenceParticipationStatus::UP_TO_DATE; 215 + $message_count = $object->getMessageCount(); 179 216 } else { 180 217 $status = ConpherenceParticipationStatus::BEHIND; 218 + $message_count = 0; 181 219 } 182 220 $participants[$phid] = 183 221 id(new ConpherenceParticipant()) ··· 186 224 ->setParticipationStatus($status) 187 225 ->setDateTouched(time()) 188 226 ->setBehindTransactionPHID($xaction->getPHID()) 227 + ->setSeenMessageCount($message_count) 189 228 ->save(); 190 229 } 191 230 $object->attachParticipants($participants);
+5 -1
src/applications/conpherence/storage/ConpherenceParticipant.php
··· 9 9 protected $conpherencePHID; 10 10 protected $participationStatus; 11 11 protected $behindTransactionPHID; 12 + protected $seenMessageCount; 12 13 protected $dateTouched; 13 14 protected $settings = array(); 14 15 ··· 24 25 return nonempty($this->settings, array()); 25 26 } 26 27 27 - public function markUpToDate(ConpherenceTransaction $xaction) { 28 + public function markUpToDate( 29 + ConpherenceThread $conpherence, 30 + ConpherenceTransaction $xaction) { 28 31 if (!$this->isUpToDate()) { 29 32 $this->setParticipationStatus(ConpherenceParticipationStatus::UP_TO_DATE); 30 33 $this->setBehindTransactionPHID($xaction->getPHID()); 34 + $this->setSeenMessageCount($conpherence->getMessageCount()); 31 35 $this->save(); 32 36 } 33 37 return $this;
+4 -1
src/applications/conpherence/storage/ConpherenceThread.php
··· 9 9 protected $id; 10 10 protected $phid; 11 11 protected $title; 12 + protected $messageCount; 13 + protected $recentParticipantPHIDs = array(); 12 14 protected $imagePHIDs = array(); 13 15 protected $mailKey; 14 16 ··· 23 25 return array( 24 26 self::CONFIG_AUX_PHID => true, 25 27 self::CONFIG_SERIALIZATION => array( 26 - 'imagePHIDs' => self::SERIALIZATION_JSON, 28 + 'recentParticipantPHIDs' => self::SERIALIZATION_JSON, 29 + 'imagePHIDs' => self::SERIALIZATION_JSON, 27 30 ), 28 31 ) + parent::getConfiguration(); 29 32 }
+8 -1
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1226 1226 'type' => 'sql', 1227 1227 'name' => $this->getPatchPath('20130330.phrequent.sql'), 1228 1228 ), 1229 + '20130403.conpherencecache.sql' => array( 1230 + 'type' => 'sql', 1231 + 'name' => $this->getPatchPath('20130403.conpherencecache.sql'), 1232 + ), 1233 + '20130403.conpherencecachemig.php' => array( 1234 + 'type' => 'php', 1235 + 'name' => $this->getPatchPath('20130403.conpherencecachemig.php'), 1236 + ) 1229 1237 ); 1230 1238 } 1231 - 1232 1239 }