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

Allow the fulltext index to select only transactions with comments

Summary:
Ref T12997. Although we can't query by transaction type (since we can't easily enumerate all possible types which may have comments -- inline types may also have comments), we //can// just check if there's a comment row or not.

This reduces the amount of garbage we need to load to rebuild indexes for unusual objects with hundreds and hundreds of mentions.

Test Plan:
- Used batch editor to mention a task 700 times.
- Indexed it before and after this change, saw index time drop from {nav 1600ms > 160ms}.
- Made some new comments on it, verified that they still indexed/queried properly.
- Browsed around, made normal transactions, made inline comments.
- Added a unique word to an inline comment, indexed revision, searched for word, found revision.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T12997

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

+62 -32
+1
src/applications/transactions/engineextension/PhabricatorTransactionsFulltextEngineExtension.php
··· 25 25 $xactions = $query 26 26 ->setViewer($this->getViewer()) 27 27 ->withObjectPHIDs(array($object->getPHID())) 28 + ->withComments(true) 28 29 ->needComments(true) 29 30 ->execute(); 30 31
+61 -32
src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php
··· 7 7 private $objectPHIDs; 8 8 private $authorPHIDs; 9 9 private $transactionTypes; 10 + private $withComments; 10 11 11 12 private $needComments = true; 12 13 private $needHandles = true; ··· 34 35 35 36 abstract public function getTemplateApplicationTransaction(); 36 37 37 - protected function buildMoreWhereClauses(AphrontDatabaseConnection $conn_r) { 38 - return array(); 39 - } 40 - 41 38 public function withPHIDs(array $phids) { 42 39 $this->phids = $phids; 43 40 return $this; ··· 58 55 return $this; 59 56 } 60 57 58 + public function withComments($with_comments) { 59 + $this->withComments = $with_comments; 60 + return $this; 61 + } 62 + 61 63 public function needComments($need) { 62 64 $this->needComments = $need; 63 65 return $this; ··· 70 72 71 73 protected function loadPage() { 72 74 $table = $this->getTemplateApplicationTransaction(); 73 - $conn_r = $table->establishConnection('r'); 74 75 75 - $data = queryfx_all( 76 - $conn_r, 77 - 'SELECT * FROM %T x %Q %Q %Q', 78 - $table->getTableName(), 79 - $this->buildWhereClause($conn_r), 80 - $this->buildOrderClause($conn_r), 81 - $this->buildLimitClause($conn_r)); 82 - 83 - $xactions = $table->loadAllFromArray($data); 76 + $xactions = $this->loadStandardPage($table); 84 77 85 78 foreach ($xactions as $xaction) { 86 79 $xaction->attachViewer($this->getViewer()); ··· 161 154 return $xactions; 162 155 } 163 156 164 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 165 - $where = array(); 157 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 158 + $where = parent::buildWhereClauseParts($conn); 166 159 167 - if ($this->phids) { 160 + if ($this->phids !== null) { 168 161 $where[] = qsprintf( 169 - $conn_r, 170 - 'phid IN (%Ls)', 162 + $conn, 163 + 'x.phid IN (%Ls)', 171 164 $this->phids); 172 165 } 173 166 174 - if ($this->objectPHIDs) { 167 + if ($this->objectPHIDs !== null) { 175 168 $where[] = qsprintf( 176 - $conn_r, 177 - 'objectPHID IN (%Ls)', 169 + $conn, 170 + 'x.objectPHID IN (%Ls)', 178 171 $this->objectPHIDs); 179 172 } 180 173 181 - if ($this->authorPHIDs) { 174 + if ($this->authorPHIDs !== null) { 182 175 $where[] = qsprintf( 183 - $conn_r, 184 - 'authorPHID IN (%Ls)', 176 + $conn, 177 + 'x.authorPHID IN (%Ls)', 185 178 $this->authorPHIDs); 186 179 } 187 180 188 - if ($this->transactionTypes) { 181 + if ($this->transactionTypes !== null) { 189 182 $where[] = qsprintf( 190 - $conn_r, 191 - 'transactionType IN (%Ls)', 183 + $conn, 184 + 'x.transactionType IN (%Ls)', 192 185 $this->transactionTypes); 193 186 } 194 187 195 - foreach ($this->buildMoreWhereClauses($conn_r) as $clause) { 196 - $where[] = $clause; 188 + if ($this->withComments !== null) { 189 + if (!$this->withComments) { 190 + $where[] = qsprintf( 191 + $conn, 192 + 'c.id IS NULL'); 193 + } 197 194 } 198 195 199 - $where[] = $this->buildPagingClause($conn_r); 196 + return $where; 197 + } 198 + 199 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 200 + $joins = parent::buildJoinClauseParts($conn); 201 + 202 + if ($this->withComments !== null) { 203 + $xaction = $this->getTemplateApplicationTransaction(); 204 + $comment = $xaction->getApplicationTransactionCommentObject(); 200 205 201 - return $this->formatWhereClause($where); 206 + if ($this->withComments) { 207 + $joins[] = qsprintf( 208 + $conn, 209 + 'JOIN %T c ON x.phid = c.transactionPHID', 210 + $comment->getTableName()); 211 + } else { 212 + $joins[] = qsprintf( 213 + $conn, 214 + 'LEFT JOIN %T c ON x.phid = c.transactionPHID', 215 + $comment->getTableName()); 216 + } 217 + } 218 + 219 + return $joins; 202 220 } 203 221 222 + protected function shouldGroupQueryResultRows() { 223 + if ($this->withComments !== null) { 224 + return true; 225 + } 226 + 227 + return parent::shouldGroupQueryResultRows(); 228 + } 204 229 205 230 public function getQueryApplicationClass() { 206 231 // TODO: Sort this out? 207 232 return null; 233 + } 234 + 235 + protected function getPrimaryTableAlias() { 236 + return 'x'; 208 237 } 209 238 210 239 }