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

Align "RevisionQuery->needCommitPHIDs()" to use Edges, not the legacy table

Summary:
Depends on D20458. Ref T13276. Although I'm not thrilled about "needCommitPHIDs()", it has a few callers, including custom fields. Allow "need + attach + get" to survive for now since they're reasonably modern, at least.

However, use edges instead of "TABLE_COMMIT" and require `need...()` + `get...()`, removing the direct `load...()`.

Also remove `RevisionQuery->withCommitPHIDs(...)`, which has no callers.

Test Plan:
- Grepped for `loadCommitPHIDs` (only two hits, the private `RevisionQuery` method).
- Called "differential.getrevision", got commits.
- Viewed a revision, saw "Commits: ...".
- Grepped for `withCommitPHIDs()`, no callers on `RevisionQuery` (some other query classes have methods with this name).
- Called "differential.query", got commits.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13276

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

+27 -61
+2 -1
src/applications/differential/conduit/DifferentialGetRevisionConduitAPIMethod.php
··· 43 43 ->withIDs(array($revision_id)) 44 44 ->setViewer($request->getUser()) 45 45 ->needReviewers(true) 46 + ->needCommitPHIDs(true) 46 47 ->executeOne(); 47 48 48 49 if (!$revision) { ··· 59 60 $diff_dicts = mpull($diffs, 'getDiffDict'); 60 61 61 62 $commit_dicts = array(); 62 - $commit_phids = $revision->loadCommitPHIDs(); 63 + $commit_phids = $revision->getCommitPHIDs(); 63 64 $handles = id(new PhabricatorHandleQuery()) 64 65 ->setViewer($request->getUser()) 65 66 ->withPHIDs($commit_phids)
+2 -1
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 51 51 ->setViewer($viewer) 52 52 ->needReviewers(true) 53 53 ->needReviewerAuthority(true) 54 + ->needCommitPHIDs(true) 54 55 ->executeOne(); 55 56 if (!$revision) { 56 57 return new Aphront404Response(); ··· 146 147 $object_phids = array_merge( 147 148 $revision->getReviewerPHIDs(), 148 149 $subscriber_phids, 149 - $revision->loadCommitPHIDs(), 150 + $revision->getCommitPHIDs(), 150 151 array( 151 152 $revision->getAuthorPHID(), 152 153 $viewer->getPHID(),
+20 -41
src/applications/differential/query/DifferentialRevisionQuery.php
··· 16 16 private $reviewers = array(); 17 17 private $revIDs = array(); 18 18 private $commitHashes = array(); 19 - private $commitPHIDs = array(); 20 19 private $phids = array(); 21 20 private $responsibles = array(); 22 21 private $branches = array(); ··· 116 115 */ 117 116 public function withCommitHashes(array $commit_hashes) { 118 117 $this->commitHashes = $commit_hashes; 119 - return $this; 120 - } 121 - 122 - /** 123 - * Filter results to revisions that have one of the provided PHIDs as 124 - * commits. Calling this function will clear anything set by previous calls 125 - * to @{method:withCommitPHIDs}. 126 - * 127 - * @param array List of PHIDs of commits 128 - * @return this 129 - * @task config 130 - */ 131 - public function withCommitPHIDs(array $commit_phids) { 132 - $this->commitPHIDs = $commit_phids; 133 118 return $this; 134 119 } 135 120 ··· 400 385 $conn_r = $table->establishConnection('r'); 401 386 402 387 if ($this->needCommitPHIDs) { 403 - $this->loadCommitPHIDs($conn_r, $revisions); 388 + $this->loadCommitPHIDs($revisions); 404 389 } 405 390 406 391 $need_active = $this->needActiveDiffs; ··· 606 591 $this->draftAuthors); 607 592 } 608 593 609 - if ($this->commitPHIDs) { 610 - $joins[] = qsprintf( 611 - $conn, 612 - 'JOIN %T commits ON commits.revisionID = r.id', 613 - DifferentialRevision::TABLE_COMMIT); 614 - } 615 - 616 594 $joins[] = $this->buildJoinClauseParts($conn); 617 595 618 596 return $this->formatJoinClause($conn, $joins); ··· 672 650 } 673 651 $hash_clauses = qsprintf($conn, '%LO', $hash_clauses); 674 652 $where[] = $hash_clauses; 675 - } 676 - 677 - if ($this->commitPHIDs) { 678 - $where[] = qsprintf( 679 - $conn, 680 - 'commits.commitPHID IN (%Ls)', 681 - $this->commitPHIDs); 682 653 } 683 654 684 655 if ($this->phids) { ··· 807 778 ); 808 779 } 809 780 810 - private function loadCommitPHIDs($conn_r, array $revisions) { 781 + private function loadCommitPHIDs(array $revisions) { 811 782 assert_instances_of($revisions, 'DifferentialRevision'); 812 - $commit_phids = queryfx_all( 813 - $conn_r, 814 - 'SELECT * FROM %T WHERE revisionID IN (%Ld)', 815 - DifferentialRevision::TABLE_COMMIT, 816 - mpull($revisions, 'getID')); 817 - $commit_phids = igroup($commit_phids, 'revisionID'); 818 - foreach ($revisions as $revision) { 819 - $phids = idx($commit_phids, $revision->getID(), array()); 820 - $phids = ipull($phids, 'commitPHID'); 821 - $revision->attachCommitPHIDs($phids); 783 + 784 + if (!$revisions) { 785 + return; 786 + } 787 + 788 + $revisions = mpull($revisions, null, 'getPHID'); 789 + 790 + $edge_query = id(new PhabricatorEdgeQuery()) 791 + ->withSourcePHIDs(array_keys($revisions)) 792 + ->withEdgeTypes( 793 + array( 794 + DifferentialRevisionHasCommitEdgeType::EDGECONST, 795 + )); 796 + $edge_query->execute(); 797 + 798 + foreach ($revisions as $phid => $revision) { 799 + $commit_phids = $edge_query->getDestinationPHIDs(array($phid)); 800 + $revision->attachCommitPHIDs($commit_phids); 822 801 } 823 802 } 824 803
+3 -18
src/applications/differential/storage/DifferentialRevision.php
··· 41 41 protected $editPolicy = PhabricatorPolicies::POLICY_USER; 42 42 protected $properties = array(); 43 43 44 - private $commits = self::ATTACHABLE; 44 + private $commitPHIDs = self::ATTACHABLE; 45 45 private $activeDiff = self::ATTACHABLE; 46 46 private $diffIDs = self::ATTACHABLE; 47 47 private $hashes = self::ATTACHABLE; ··· 158 158 return '/'.$this->getMonogram(); 159 159 } 160 160 161 - public function loadCommitPHIDs() { 162 - if (!$this->getID()) { 163 - return ($this->commits = array()); 164 - } 165 - 166 - $commits = queryfx_all( 167 - $this->establishConnection('r'), 168 - 'SELECT commitPHID FROM %T WHERE revisionID = %d', 169 - self::TABLE_COMMIT, 170 - $this->getID()); 171 - $commits = ipull($commits, 'commitPHID'); 172 - 173 - return ($this->commits = $commits); 174 - } 175 - 176 161 public function getCommitPHIDs() { 177 - return $this->assertAttached($this->commits); 162 + return $this->assertAttached($this->commitPHIDs); 178 163 } 179 164 180 165 public function getActiveDiff() { ··· 202 187 } 203 188 204 189 public function attachCommitPHIDs(array $phids) { 205 - $this->commits = array_values($phids); 190 + $this->commitPHIDs = $phids; 206 191 return $this; 207 192 } 208 193