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

Abstract access to DifferentialInlineComment behind a Query

Summary:
Ref T2222. See D6260.

Push all this junk behind a Query so I can move the storage out from underneath it.

Test Plan: Viewed home page, list view, revision. Made draft, looked at preview, submitted draft, viewed inline, replied to inline.

Reviewers: btrahan

Reviewed By: btrahan

CC: chad, aran

Maniphest Tasks: T2222

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

+165 -41
+2
src/__phutil_library_map__.php
··· 370 370 'DifferentialInlineCommentEditController' => 'applications/differential/controller/DifferentialInlineCommentEditController.php', 371 371 'DifferentialInlineCommentEditView' => 'applications/differential/view/DifferentialInlineCommentEditView.php', 372 372 'DifferentialInlineCommentPreviewController' => 'applications/differential/controller/DifferentialInlineCommentPreviewController.php', 373 + 'DifferentialInlineCommentQuery' => 'applications/differential/query/DifferentialInlineCommentQuery.php', 373 374 'DifferentialInlineCommentView' => 'applications/differential/view/DifferentialInlineCommentView.php', 374 375 'DifferentialLinesFieldSpecification' => 'applications/differential/field/specification/DifferentialLinesFieldSpecification.php', 375 376 'DifferentialLintFieldSpecification' => 'applications/differential/field/specification/DifferentialLintFieldSpecification.php', ··· 2249 2250 'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController', 2250 2251 'DifferentialInlineCommentEditView' => 'AphrontView', 2251 2252 'DifferentialInlineCommentPreviewController' => 'PhabricatorInlineCommentPreviewController', 2253 + 'DifferentialInlineCommentQuery' => 'PhabricatorOffsetPagedQuery', 2252 2254 'DifferentialInlineCommentView' => 'AphrontView', 2253 2255 'DifferentialLinesFieldSpecification' => 'DifferentialFieldSpecification', 2254 2256 'DifferentialLintFieldSpecification' => 'DifferentialFieldSpecification',
+3 -3
src/applications/differential/conduit/ConduitAPI_differential_getrevisioncomments_Method.php
··· 40 40 41 41 $with_inlines = $request->getValue('inlines'); 42 42 if ($with_inlines) { 43 - $inlines = id(new DifferentialInlineComment())->loadAllWhere( 44 - 'revisionID IN (%Ld)', 45 - $revision_ids); 43 + $inlines = id(new DifferentialInlineCommentQuery()) 44 + ->withRevisionIDs($revision_ids) 45 + ->execute(); 46 46 $changesets = array(); 47 47 if ($inlines) { 48 48 $changesets = id(new DifferentialChangeset())->loadAllWhere(
+3 -4
src/applications/differential/controller/DifferentialChangesetViewController.php
··· 268 268 return; 269 269 } 270 270 271 - return id(new DifferentialInlineComment())->loadAllWhere( 272 - 'changesetID IN (%Ld) AND (commentID IS NOT NULL OR authorPHID = %s)', 273 - $changeset_ids, 274 - $author_phid); 271 + return id(new DifferentialInlineCommentQuery()) 272 + ->withAuthorAndChangesetIDs($author_phid, $changeset_ids) 273 + ->execute(); 275 274 } 276 275 277 276 private function buildRawFileResponse(
+3 -4
src/applications/differential/controller/DifferentialCommentSaveController.php
··· 39 39 ->setAddedCCs($ccs) 40 40 ->save(); 41 41 } catch (DifferentialActionHasNoEffectException $no_effect) { 42 - $has_inlines = id(new DifferentialInlineComment())->loadAllWhere( 43 - 'authorPHID = %s AND revisionID = %d AND commentID IS NULL', 44 - $request->getUser()->getPHID(), 45 - $revision->getID()); 42 + $has_inlines = id(new DifferentialInlineCommentQuery()) 43 + ->withDraftComments($request->getUser()->getPHID(), $revision->getID()) 44 + ->execute(); 46 45 47 46 $dialog = new AphrontDialogView(); 48 47 $dialog->setUser($request->getUser());
+3 -1
src/applications/differential/controller/DifferentialInlineCommentEditController.php
··· 29 29 } 30 30 31 31 protected function loadComment($id) { 32 - return id(new DifferentialInlineComment())->load($id); 32 + return id(new DifferentialInlineCommentQuery()) 33 + ->withIDs(array($id)) 34 + ->executeOne(); 33 35 } 34 36 35 37 protected function loadCommentForEdit($id) {
+3 -4
src/applications/differential/controller/DifferentialInlineCommentPreviewController.php
··· 12 12 protected function loadInlineComments() { 13 13 $user = $this->getRequest()->getUser(); 14 14 15 - $inlines = id(new DifferentialInlineComment())->loadAllWhere( 16 - 'authorPHID = %s AND revisionID = %d AND commentID IS NULL', 17 - $user->getPHID(), 18 - $this->revisionID); 15 + $inlines = id(new DifferentialInlineCommentQuery()) 16 + ->withDraftComments($user->getPHID(), $this->revisionID) 17 + ->execute(); 19 18 20 19 return $inlines; 21 20 }
+6 -10
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 194 194 pht('Show All Files Inline')))); 195 195 $warning = $warning->render(); 196 196 197 - $my_inlines = id(new DifferentialInlineComment())->loadAllWhere( 198 - 'revisionID = %d AND commentID IS NULL AND authorPHID = %s AND '. 199 - 'changesetID IN (%Ld)', 200 - $this->revisionID, 201 - $user->getPHID(), 202 - mpull($changesets, 'getID')); 197 + $my_inlines = id(new DifferentialInlineCommentQuery()) 198 + ->withDraftComments($user->getPHID(), $this->revisionID) 199 + ->execute(); 203 200 204 201 $visible_changesets = array(); 205 202 foreach ($inlines + $my_inlines as $inline) { ··· 643 640 return $inline_comments; 644 641 } 645 642 646 - $inline_comments = id(new DifferentialInlineComment()) 647 - ->loadAllWhere( 648 - 'commentID in (%Ld)', 649 - $comment_ids); 643 + $inline_comments = id(new DifferentialInlineCommentQuery()) 644 + ->withCommentIDs($comment_ids) 645 + ->execute(); 650 646 651 647 $load_changesets = array(); 652 648 foreach ($inline_comments as $inline) {
+3 -4
src/applications/differential/editor/DifferentialCommentEditor.php
··· 116 116 117 117 $inline_comments = array(); 118 118 if ($this->attachInlineComments) { 119 - $inline_comments = id(new DifferentialInlineComment())->loadAllWhere( 120 - 'authorPHID = %s AND revisionID = %d AND commentID IS NULL', 121 - $actor_phid, 122 - $revision->getID()); 119 + $inline_comments = id(new DifferentialInlineCommentQuery()) 120 + ->withDraftComments($actor_phid, $revision->getID()) 121 + ->execute(); 123 122 } 124 123 125 124 switch ($action) {
+129
src/applications/differential/query/DifferentialInlineCommentQuery.php
··· 1 + <?php 2 + 3 + /** 4 + * Temporary wrapper for transitioning Differential to ApplicationTransactions. 5 + */ 6 + final class DifferentialInlineCommentQuery 7 + extends PhabricatorOffsetPagedQuery { 8 + 9 + private $revisionIDs; 10 + private $notDraft; 11 + private $ids; 12 + private $commentIDs; 13 + 14 + private $authorAndChangesetIDs; 15 + private $draftComments; 16 + private $draftsByAuthors; 17 + 18 + public function withRevisionIDs(array $ids) { 19 + $this->revisionIDs = $ids; 20 + return $this; 21 + } 22 + 23 + public function withNotDraft($not_draft) { 24 + $this->notDraft = $not_draft; 25 + return $this; 26 + } 27 + 28 + public function withIDs(array $ids) { 29 + $this->ids = $ids; 30 + return $this; 31 + } 32 + 33 + public function withCommentIDs(array $ids) { 34 + $this->commentIDs = $ids; 35 + return $this; 36 + } 37 + 38 + public function withAuthorAndChangesetIDs($author_phid, array $ids) { 39 + $this->authorAndChangesetIDs = array($author_phid, $ids); 40 + return $this; 41 + } 42 + 43 + public function withDraftComments($author_phid, $revision_id) { 44 + $this->draftComments = array($author_phid, $revision_id); 45 + return $this; 46 + } 47 + 48 + public function withDraftsByAuthors(array $author_phids) { 49 + $this->draftsByAuthors = $author_phids; 50 + return $this; 51 + } 52 + 53 + public function execute() { 54 + $table = new DifferentialInlineComment(); 55 + $conn_r = $table->establishConnection('r'); 56 + 57 + $data = queryfx_all( 58 + $conn_r, 59 + 'SELECT * FROM %T %Q %Q', 60 + $table->getTableName(), 61 + $this->buildWhereClause($conn_r), 62 + $this->buildLimitClause($conn_r)); 63 + 64 + return $table->loadAllFromArray($data); 65 + } 66 + 67 + public function executeOne() { 68 + return head($this->execute()); 69 + } 70 + 71 + private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 72 + $where = array(); 73 + 74 + if ($this->revisionIDs) { 75 + $where[] = qsprintf( 76 + $conn_r, 77 + 'revisionID IN (%Ld)', 78 + $this->revisionIDs); 79 + } 80 + 81 + if ($this->notDraft) { 82 + $where[] = qsprintf( 83 + $conn_r, 84 + 'commentID IS NOT NULL'); 85 + } 86 + 87 + if ($this->ids) { 88 + $where[] = qsprintf( 89 + $conn_r, 90 + 'id IN (%Ld)', 91 + $this->ids); 92 + } 93 + 94 + if ($this->commentIDs) { 95 + $where[] = qsprintf( 96 + $conn_r, 97 + 'commentID in (%Ld)', 98 + $this->commentIDs); 99 + } 100 + 101 + if ($this->authorAndChangesetIDs) { 102 + list($phid, $ids) = $this->authorAndChangesetIDs; 103 + $where[] = qsprintf( 104 + $conn_r, 105 + 'authorPHID = %s AND changesetID IN (%Ld)', 106 + $phid, 107 + $ids); 108 + } 109 + 110 + if ($this->draftComments) { 111 + list($phid, $rev_id) = $this->draftComments; 112 + $where[] = qsprintf( 113 + $conn_r, 114 + 'authorPHID = %s AND revisionID = %d AND commentID IS NULL', 115 + $phid, 116 + $rev_id); 117 + } 118 + 119 + if ($this->draftsByAuthors) { 120 + $where[] = qsprintf( 121 + $conn_r, 122 + 'authorPHID IN (%Ls) AND commentID IS NULL', 123 + $this->draftsByAuthors); 124 + } 125 + 126 + return $this->formatWhereClause($where); 127 + } 128 + 129 + }
+3 -3
src/applications/differential/query/DifferentialRevisionQuery.php
··· 492 492 $this->draftRevisions[] = substr($draft->getDraftKey(), $len); 493 493 } 494 494 495 - $inlines = id(new DifferentialInlineComment())->loadAllWhere( 496 - 'commentID IS NULL AND authorPHID IN (%Ls)', 497 - $this->draftAuthors); 495 + $inlines = id(new DifferentialInlineCommentQuery()) 496 + ->withDraftsByAuthors($this->draftAuthors) 497 + ->execute(); 498 498 foreach ($inlines as $inline) { 499 499 $this->draftRevisions[] = $inline->getRevisionID(); 500 500 }
+4 -5
src/applications/differential/search/DifferentialSearchIndexer.php
··· 57 57 ->withRevisionIDs(array($rev->getID())) 58 58 ->execute(); 59 59 60 - $inlines = $rev->loadRelatives( 61 - new DifferentialInlineComment(), 62 - 'revisionID', 63 - 'getID', 64 - '(commentID IS NOT NULL)'); 60 + $inlines = id(new DifferentialInlineCommentQuery()) 61 + ->withRevisionIDs(array($rev->getID())) 62 + ->withNotDraft(true) 63 + ->execute(); 65 64 66 65 $touches = array(); 67 66
+3 -3
src/applications/differential/storage/DifferentialRevision.php
··· 199 199 $comment->delete(); 200 200 } 201 201 202 - $inlines = id(new DifferentialInlineComment())->loadAllWhere( 203 - 'revisionID = %d', 204 - $this->getID()); 202 + $inlines = id(new DifferentialInlineCommentQuery()) 203 + ->withRevisionIDs(array($this->getID())) 204 + ->execute(); 205 205 foreach ($inlines as $inline) { 206 206 $inline->delete(); 207 207 }