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

Extend TransactionCommentQuery for Diffusion

Summary: Ref T2009. Ref T1460. Reduces the amount of garbage involved in loading inline comments and routes more pathways through the proper Query layer.

Test Plan: Viewed, edited, previewed, submitted inline comments in Diffusion.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2009, T1460

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

+79 -55
+2
src/__phutil_library_map__.php
··· 491 491 'DiffusionDefaultPushCapability' => 'applications/diffusion/capability/DiffusionDefaultPushCapability.php', 492 492 'DiffusionDefaultViewCapability' => 'applications/diffusion/capability/DiffusionDefaultViewCapability.php', 493 493 'DiffusionDiffController' => 'applications/diffusion/controller/DiffusionDiffController.php', 494 + 'DiffusionDiffInlineCommentQuery' => 'applications/diffusion/query/DiffusionDiffInlineCommentQuery.php', 494 495 'DiffusionDiffQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionDiffQueryConduitAPIMethod.php', 495 496 'DiffusionDoorkeeperCommitFeedStoryPublisher' => 'applications/diffusion/doorkeeper/DiffusionDoorkeeperCommitFeedStoryPublisher.php', 496 497 'DiffusionEmptyResultView' => 'applications/diffusion/view/DiffusionEmptyResultView.php', ··· 3644 3645 'DiffusionDefaultPushCapability' => 'PhabricatorPolicyCapability', 3645 3646 'DiffusionDefaultViewCapability' => 'PhabricatorPolicyCapability', 3646 3647 'DiffusionDiffController' => 'DiffusionController', 3648 + 'DiffusionDiffInlineCommentQuery' => 'PhabricatorDiffInlineCommentQuery', 3647 3649 'DiffusionDiffQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod', 3648 3650 'DiffusionDoorkeeperCommitFeedStoryPublisher' => 'DoorkeeperFeedStoryPublisher', 3649 3651 'DiffusionEmptyResultView' => 'DiffusionView',
+15 -14
src/applications/audit/storage/PhabricatorAuditInlineComment.php
··· 61 61 PhabricatorUser $viewer, 62 62 $commit_phid) { 63 63 64 - $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 65 - 'authorPHID = %s AND commitPHID = %s AND transactionPHID IS NULL 66 - AND pathID IS NOT NULL 67 - AND isDeleted = 0', 68 - $viewer->getPHID(), 69 - $commit_phid); 70 - 71 - $inlines = PhabricatorInlineCommentController::loadAndAttachReplies( 72 - $viewer, 73 - $inlines); 64 + $inlines = id(new DiffusionDiffInlineCommentQuery()) 65 + ->setViewer($viewer) 66 + ->withAuthorPHIDs(array($viewer->getPHID())) 67 + ->withCommitPHIDs(array($commit_phid)) 68 + ->withHasTransaction(false) 69 + ->withHasPath(true) 70 + ->withIsDeleted(false) 71 + ->needReplyToComments(true) 72 + ->execute(); 74 73 75 74 return self::buildProxies($inlines); 76 75 } ··· 79 78 PhabricatorUser $viewer, 80 79 $commit_phid) { 81 80 82 - $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 83 - 'commitPHID = %s AND transactionPHID IS NOT NULL 84 - AND pathID IS NOT NULL', 85 - $commit_phid); 81 + $inlines = id(new DiffusionDiffInlineCommentQuery()) 82 + ->setViewer($viewer) 83 + ->withCommitPHIDs(array($commit_phid)) 84 + ->withHasTransaction(true) 85 + ->withHasPath(true) 86 + ->execute(); 86 87 87 88 return self::buildProxies($inlines); 88 89 }
+62
src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php
··· 1 + <?php 2 + 3 + final class DiffusionDiffInlineCommentQuery 4 + extends PhabricatorDiffInlineCommentQuery { 5 + 6 + private $commitPHIDs; 7 + private $hasPath; 8 + private $pathIDs; 9 + 10 + public function withCommitPHIDs(array $phids) { 11 + $this->commitPHIDs = $phids; 12 + return $this; 13 + } 14 + 15 + public function withHasPath($has_path) { 16 + $this->hasPath = $has_path; 17 + return $this; 18 + } 19 + 20 + public function withPathIDs(array $path_ids) { 21 + $this->pathIDs = $path_ids; 22 + return $this; 23 + } 24 + 25 + protected function getTemplate() { 26 + return new PhabricatorAuditTransactionComment(); 27 + } 28 + 29 + protected function buildWhereClauseComponents( 30 + AphrontDatabaseConnection $conn_r) { 31 + $where = parent::buildWhereClauseComponents($conn_r); 32 + 33 + if ($this->commitPHIDs !== null) { 34 + $where[] = qsprintf( 35 + $conn_r, 36 + 'xcomment.commitPHID IN (%Ls)', 37 + $this->commitPHIDs); 38 + } 39 + 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 + if ($this->pathIDs !== null) { 53 + $where[] = qsprintf( 54 + $conn_r, 55 + 'xcomment.pathID IN (%Ld)', 56 + $this->pathIDs); 57 + } 58 + 59 + return $where; 60 + } 61 + 62 + }
-41
src/infrastructure/diff/PhabricatorInlineCommentController.php
··· 309 309 ->addRowScaffold($view); 310 310 } 311 311 312 - public static function loadAndAttachReplies( 313 - PhabricatorUser $viewer, 314 - array $comments) { 315 - // TODO: This code doesn't really belong here, but we don't have a much 316 - // better place to put it at the moment. 317 - 318 - if (!$comments) { 319 - return $comments; 320 - } 321 - 322 - $template = head($comments); 323 - 324 - $reply_phids = array(); 325 - foreach ($comments as $comment) { 326 - $reply_phid = $comment->getReplyToCommentPHID(); 327 - if ($reply_phid) { 328 - $reply_phids[] = $reply_phid; 329 - } 330 - } 331 - 332 - if ($reply_phids) { 333 - $reply_comments = 334 - id(new PhabricatorApplicationTransactionTemplatedCommentQuery()) 335 - ->setTemplate($template) 336 - ->setViewer($viewer) 337 - ->withPHIDs($reply_phids) 338 - ->execute(); 339 - $reply_comments = mpull($reply_comments, null, 'getPHID'); 340 - } else { 341 - $reply_comments = array(); 342 - } 343 - 344 - foreach ($comments as $comment) { 345 - $reply_phid = $comment->getReplyToCommentPHID(); 346 - $reply = idx($reply_comments, $reply_phid); 347 - $comment->attachReplyToComment($reply); 348 - } 349 - 350 - return $comments; 351 - } 352 - 353 312 }