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

Make InlineCommentQueries more robust/consistent

Summary:
Ref T13513. Improve consistency and robustness of the "InlineComment" queries.

The only real change here is that these queries now implicitly add a clause for selecting inlines ("pathID IS NULL" or "changesetID IS NULL").

Test Plan: Browed, created, edited, and submitted inlines.

Maniphest Tasks: T13513

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

+92 -71
-2
src/applications/audit/storage/PhabricatorAuditInlineComment.php
··· 65 65 ->withAuthorPHIDs(array($viewer->getPHID())) 66 66 ->withCommitPHIDs(array($commit_phid)) 67 67 ->withHasTransaction(false) 68 - ->withHasPath(true) 69 68 ->withIsDeleted(false) 70 69 ->needReplyToComments(true) 71 70 ->execute(); ··· 85 84 ->setViewer($viewer) 86 85 ->withCommitPHIDs(array($commit_phid)) 87 86 ->withHasTransaction(true) 88 - ->withHasPath(true) 89 87 ->execute(); 90 88 91 89 return self::buildProxies($inlines);
+24 -7
src/applications/differential/query/DifferentialDiffInlineCommentQuery.php
··· 5 5 6 6 private $revisionPHIDs; 7 7 8 + protected function newApplicationTransactionCommentTemplate() { 9 + return new DifferentialTransactionComment(); 10 + } 11 + 8 12 public function withRevisionPHIDs(array $phids) { 9 13 $this->revisionPHIDs = $phids; 10 14 return $this; 11 15 } 12 16 13 - protected function getTemplate() { 14 - return new DifferentialTransactionComment(); 17 + public function withObjectPHIDs(array $phids) { 18 + return $this->withRevisionPHIDs($phids); 19 + } 20 + 21 + protected function buildInlineCommentWhereClauseParts( 22 + AphrontDatabaseConnection $conn) { 23 + $where = array(); 24 + $alias = $this->getPrimaryTableAlias(); 25 + 26 + $where[] = qsprintf( 27 + $conn, 28 + 'changesetID IS NOT NULL'); 29 + 30 + return $where; 15 31 } 16 32 17 - protected function buildWhereClauseComponents( 18 - AphrontDatabaseConnection $conn_r) { 19 - $where = parent::buildWhereClauseComponents($conn_r); 33 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 34 + $where = parent::buildWhereClauseParts($conn); 35 + $alias = $this->getPrimaryTableAlias(); 20 36 21 37 if ($this->revisionPHIDs !== null) { 22 38 $where[] = qsprintf( 23 - $conn_r, 24 - 'revisionPHID IN (%Ls)', 39 + $conn, 40 + '%T.revisionPHID IN (%Ls)', 41 + $alias, 25 42 $this->revisionPHIDs); 26 43 } 27 44
+26 -25
src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php
··· 4 4 extends PhabricatorDiffInlineCommentQuery { 5 5 6 6 private $commitPHIDs; 7 - private $hasPath; 8 7 private $pathIDs; 9 8 9 + protected function newApplicationTransactionCommentTemplate() { 10 + return new PhabricatorAuditTransactionComment(); 11 + } 12 + 10 13 public function withCommitPHIDs(array $phids) { 11 14 $this->commitPHIDs = $phids; 12 15 return $this; 13 16 } 14 17 15 - public function withHasPath($has_path) { 16 - $this->hasPath = $has_path; 17 - return $this; 18 + public function withObjectPHIDs(array $phids) { 19 + return $this->withCommitPHIDs($phids); 18 20 } 19 21 20 22 public function withPathIDs(array $path_ids) { ··· 22 24 return $this; 23 25 } 24 26 25 - protected function getTemplate() { 26 - return new PhabricatorAuditTransactionComment(); 27 + protected function buildInlineCommentWhereClauseParts( 28 + AphrontDatabaseConnection $conn) { 29 + $where = array(); 30 + $alias = $this->getPrimaryTableAlias(); 31 + 32 + $where[] = qsprintf( 33 + $conn, 34 + '%T.pathID IS NOT NULL', 35 + $alias); 36 + 37 + return $where; 27 38 } 28 39 29 - protected function buildWhereClauseComponents( 30 - AphrontDatabaseConnection $conn_r) { 31 - $where = parent::buildWhereClauseComponents($conn_r); 40 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 41 + $where = parent::buildWhereClauseParts($conn); 42 + $alias = $this->getPrimaryTableAlias(); 32 43 33 44 if ($this->commitPHIDs !== null) { 34 45 $where[] = qsprintf( 35 - $conn_r, 36 - 'xcomment.commitPHID IN (%Ls)', 46 + $conn, 47 + '%T.commitPHID IN (%Ls)', 48 + $alias, 37 49 $this->commitPHIDs); 38 50 } 39 51 40 - if ($this->hasPath !== null) { 41 - if ($this->hasPath) { 42 - $where[] = qsprintf( 43 - $conn_r, 44 - 'xcomment.pathID IS NOT NULL'); 45 - } else { 46 - $where[] = qsprintf( 47 - $conn_r, 48 - 'xcomment.pathID IS NULL'); 49 - } 50 - } 51 - 52 52 if ($this->pathIDs !== null) { 53 53 $where[] = qsprintf( 54 - $conn_r, 55 - 'xcomment.pathID IN (%Ld)', 54 + $conn, 55 + '%T.pathID IN (%Ld)', 56 + $alias, 56 57 $this->pathIDs); 57 58 } 58 59
+26 -30
src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php
··· 10 10 private $isDeleted; 11 11 private $hasTransaction; 12 12 13 - abstract protected function getTemplate(); 13 + abstract protected function newApplicationTransactionCommentTemplate(); 14 14 15 15 public function withIDs(array $ids) { 16 16 $this->ids = $ids; ··· 42 42 return $this; 43 43 } 44 44 45 - protected function loadPage() { 46 - $table = $this->getTemplate(); 47 - $conn_r = $table->establishConnection('r'); 48 - 49 - $data = queryfx_all( 50 - $conn_r, 51 - 'SELECT * FROM %T xcomment %Q %Q %Q', 52 - $table->getTableName(), 53 - $this->buildWhereClause($conn_r), 54 - $this->buildOrderClause($conn_r), 55 - $this->buildLimitClause($conn_r)); 56 - 57 - return $table->loadAllFromArray($data); 45 + public function newResultObject() { 46 + return $this->newApplicationTransactionCommentTemplate(); 58 47 } 59 48 60 - protected function buildWhereClause(AphrontDatabaseConnection $conn) { 61 - return $this->formatWhereClause( 62 - $conn, 63 - $this->buildWhereClauseComponents($conn)); 49 + protected function loadPage() { 50 + return $this->loadStandardPage($this->newResultObject()); 64 51 } 65 52 66 - protected function buildWhereClauseComponents( 67 - AphrontDatabaseConnection $conn) { 68 - 69 - $where = array(); 53 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 54 + $where = parent::buildWhereClauseParts($conn); 55 + $alias = $this->getPrimaryTableAlias(); 70 56 71 57 if ($this->ids !== null) { 72 58 $where[] = qsprintf( 73 59 $conn, 74 - 'xcomment.id IN (%Ld)', 60 + '%T.id IN (%Ld)', 61 + $alias, 75 62 $this->ids); 76 63 } 77 64 78 65 if ($this->phids !== null) { 79 66 $where[] = qsprintf( 80 67 $conn, 81 - 'xcomment.phid IN (%Ls)', 68 + '%T.phid IN (%Ls)', 69 + $alias, 82 70 $this->phids); 83 71 } 84 72 85 73 if ($this->authorPHIDs !== null) { 86 74 $where[] = qsprintf( 87 75 $conn, 88 - 'xcomment.authorPHID IN (%Ls)', 76 + '%T.authorPHID IN (%Ls)', 77 + $alias, 89 78 $this->authorPHIDs); 90 79 } 91 80 92 81 if ($this->transactionPHIDs !== null) { 93 82 $where[] = qsprintf( 94 83 $conn, 95 - 'xcomment.transactionPHID IN (%Ls)', 84 + '%T.transactionPHID IN (%Ls)', 85 + $alias, 96 86 $this->transactionPHIDs); 97 87 } 98 88 99 89 if ($this->isDeleted !== null) { 100 90 $where[] = qsprintf( 101 91 $conn, 102 - 'xcomment.isDeleted = %d', 92 + '%T.isDeleted = %d', 93 + $alias, 103 94 (int)$this->isDeleted); 104 95 } 105 96 ··· 107 98 if ($this->hasTransaction) { 108 99 $where[] = qsprintf( 109 100 $conn, 110 - 'xcomment.transactionPHID IS NOT NULL'); 101 + '%T.transactionPHID IS NOT NULL', 102 + $alias); 111 103 } else { 112 104 $where[] = qsprintf( 113 105 $conn, 114 - 'xcomment.transactionPHID IS NULL'); 106 + '%T.transactionPHID IS NULL', 107 + $alias); 115 108 } 116 109 } 117 110 118 111 return $where; 119 112 } 120 113 114 + protected function getPrimaryTableAlias() { 115 + return 'xcomment'; 116 + } 117 + 121 118 public function getQueryApplicationClass() { 122 119 // TODO: Figure out the app via the template? 123 120 return null; 124 121 } 125 - 126 122 127 123 }
+2 -2
src/applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php
··· 11 11 return $this; 12 12 } 13 13 14 - protected function getTemplate() { 15 - return $this->template; 14 + protected function newApplicationTransactionCommentTemplate() { 15 + return id(clone $this->template); 16 16 } 17 17 18 18 }
+14 -5
src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php
··· 6 6 private $fixedStates; 7 7 private $needReplyToComments; 8 8 9 + abstract protected function buildInlineCommentWhereClauseParts( 10 + AphrontDatabaseConnection $conn); 11 + abstract public function withObjectPHIDs(array $phids); 12 + 9 13 public function withFixedStates(array $states) { 10 14 $this->fixedStates = $states; 11 15 return $this; ··· 16 20 return $this; 17 21 } 18 22 19 - protected function buildWhereClauseComponents( 20 - AphrontDatabaseConnection $conn_r) { 21 - $where = parent::buildWhereClauseComponents($conn_r); 23 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 24 + $where = parent::buildWhereClauseParts($conn); 25 + $alias = $this->getPrimaryTableAlias(); 26 + 27 + foreach ($this->buildInlineCommentWhereClauseParts($conn) as $part) { 28 + $where[] = $part; 29 + } 22 30 23 31 if ($this->fixedStates !== null) { 24 32 $where[] = qsprintf( 25 - $conn_r, 26 - 'fixedState IN (%Ls)', 33 + $conn, 34 + '%T.fixedState IN (%Ls)', 35 + $alias, 27 36 $this->fixedStates); 28 37 } 29 38