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

Remove obsolete "relationships" code from Differential

Summary:
Ref T10967. There have been two different ways to load reviewers for a while: `needReviewerStatus()` and `needRelationships()`.

The `needRelationships()` stuff was a false start along time ago that didn't really go anywhere. I believe the idea was that we might want to load several different types of edges (subscribers, reviewers, etc) on lots of different types of objects. However, all that stuff pretty much ended up modularizing so that main `Query` classes did not need to know about it, so `needRelationships()` never got generalized or went anywhere.

A handful of things still use it, but get rid of them: they should either `needReviewerStatus()` to get reviewer info, or the ~3 callsites that care about subscribers can just load them directly.

Test Plan:
- Grepped for removed methods (`needRelationships()`, `getReviewers()`, `getCCPHIDs()`, etc).
- Browsed Diffusion, Differential.
- Called `differential.query`.

It's possible I missed some stuff, but it should mostly show up as super obvious fatals ("call needReviewerStatus() before getReviewerStatus()!").

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10967

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

+35 -140
+1 -2
src/applications/differential/conduit/DifferentialGetRevisionConduitAPIMethod.php
··· 42 42 $revision = id(new DifferentialRevisionQuery()) 43 43 ->withIDs(array($revision_id)) 44 44 ->setViewer($request->getUser()) 45 - ->needRelationships(true) 46 45 ->needReviewerStatus(true) 47 46 ->executeOne(); 48 47 ··· 50 49 throw new ConduitException('ERR_BAD_REVISION'); 51 50 } 52 51 53 - $reviewer_phids = array_values($revision->getReviewers()); 52 + $reviewer_phids = $revision->getReviewerPHIDs(); 54 53 55 54 $diffs = id(new DifferentialDiffQuery()) 56 55 ->setViewer($request->getUser())
+11 -3
src/applications/differential/conduit/DifferentialQueryConduitAPIMethod.php
··· 182 182 $query->withBranches($branches); 183 183 } 184 184 185 - $query->needRelationships(true); 185 + $query->needReviewerStatus(true); 186 186 $query->needCommitPHIDs(true); 187 187 $query->needDiffIDs(true); 188 188 $query->needActiveDiffs(true); ··· 193 193 $field_data = $this->loadCustomFieldsForRevisions( 194 194 $request->getUser(), 195 195 $revisions); 196 + 197 + if ($revisions) { 198 + $ccs = id(new PhabricatorSubscribersQuery()) 199 + ->withObjectPHIDs(mpull($revisions, 'getPHID')) 200 + ->execute(); 201 + } else { 202 + $ccs = array(); 203 + } 196 204 197 205 $results = array(); 198 206 foreach ($revisions as $revision) { ··· 224 232 'activeDiffPHID' => $diff->getPHID(), 225 233 'diffs' => $revision->getDiffIDs(), 226 234 'commits' => $revision->getCommitPHIDs(), 227 - 'reviewers' => array_values($revision->getReviewers()), 228 - 'ccs' => array_values($revision->getCCPHIDs()), 235 + 'reviewers' => $revision->getReviewerPHIDs(), 236 + 'ccs' => idx($ccs, $phid, array()), 229 237 'hashes' => $revision->getHashes(), 230 238 'auxiliary' => idx($field_data, $phid, array()), 231 239 'repositoryPHID' => $diff->getRepositoryPHID(),
+6 -4
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 17 17 $revision = id(new DifferentialRevisionQuery()) 18 18 ->withIDs(array($this->revisionID)) 19 19 ->setViewer($viewer) 20 - ->needRelationships(true) 21 20 ->needReviewerStatus(true) 22 21 ->needReviewerAuthority(true) 23 22 ->executeOne(); ··· 103 102 $this->loadDiffProperties($diffs); 104 103 $props = $target_manual->getDiffProperties(); 105 104 105 + $subscriber_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID( 106 + $revision->getPHID()); 107 + 106 108 $object_phids = array_merge( 107 - $revision->getReviewers(), 108 - $revision->getCCPHIDs(), 109 + $revision->getReviewerPHIDs(), 110 + $subscriber_phids, 109 111 $revision->loadCommitPHIDs(), 110 112 array( 111 113 $revision->getAuthorPHID(), ··· 782 784 ->setLimit(10) 783 785 ->needFlags(true) 784 786 ->needDrafts(true) 785 - ->needRelationships(true); 787 + ->needReviewerStatus(true); 786 788 787 789 foreach ($path_map as $path => $path_id) { 788 790 $query->withPath($repository->getID(), $path_id);
+5 -4
src/applications/differential/doorkeeper/DifferentialDoorkeeperRevisionFeedStoryPublisher.php
··· 26 26 return id(new DifferentialRevisionQuery()) 27 27 ->setViewer($this->getViewer()) 28 28 ->withIDs(array($object->getID())) 29 - ->needRelationships(true) 29 + ->needReviewerStatus(true) 30 30 ->executeOne(); 31 31 } 32 32 ··· 37 37 public function getActiveUserPHIDs($object) { 38 38 $status = $object->getStatus(); 39 39 if ($status == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) { 40 - return $object->getReviewers(); 40 + return $object->getReviewerPHIDs(); 41 41 } else { 42 42 return array(); 43 43 } ··· 48 48 if ($status == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) { 49 49 return array(); 50 50 } else { 51 - return $object->getReviewers(); 51 + return $object->getReviewerPHIDs(); 52 52 } 53 53 } 54 54 55 55 public function getCCUserPHIDs($object) { 56 - return $object->getCCPHIDs(); 56 + return PhabricatorSubscribersQuery::loadSubscribersForPHID( 57 + $object->getPHID()); 57 58 } 58 59 59 60 public function getObjectTitle($object) {
-1
src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php
··· 85 85 $revision = id(new DifferentialRevisionQuery()) 86 86 ->withIDs(array($revision->getID())) 87 87 ->setViewer(PhabricatorUser::getOmnipotentUser()) 88 - ->needRelationships(true) 89 88 ->needReviewerStatus(true) 90 89 ->executeOne(); 91 90
-53
src/applications/differential/query/DifferentialRevisionQuery.php
··· 43 43 const ORDER_MODIFIED = 'order-modified'; 44 44 const ORDER_CREATED = 'order-created'; 45 45 46 - private $needRelationships = false; 47 46 private $needActiveDiffs = false; 48 47 private $needDiffIDs = false; 49 48 private $needCommitPHIDs = false; ··· 227 226 } 228 227 229 228 230 - 231 - /** 232 - * Set whether or not the query will load and attach relationships. 233 - * 234 - * @param bool True to load and attach relationships. 235 - * @return this 236 - * @task config 237 - */ 238 - public function needRelationships($need_relationships) { 239 - $this->needRelationships = $need_relationships; 240 - return $this; 241 - } 242 - 243 - 244 229 /** 245 230 * Set whether or not the query should load the active diff for each 246 231 * revision. ··· 424 409 425 410 $table = new DifferentialRevision(); 426 411 $conn_r = $table->establishConnection('r'); 427 - 428 - if ($this->needRelationships) { 429 - $this->loadRelationships($conn_r, $revisions); 430 - } 431 412 432 413 if ($this->needCommitPHIDs) { 433 414 $this->loadCommitPHIDs($conn_r, $revisions); ··· 852 833 'id' => $revision->getID(), 853 834 'updated' => $revision->getDateModified(), 854 835 ); 855 - } 856 - 857 - private function loadRelationships($conn_r, array $revisions) { 858 - assert_instances_of($revisions, 'DifferentialRevision'); 859 - 860 - $type_reviewer = DifferentialRevisionHasReviewerEdgeType::EDGECONST; 861 - $type_subscriber = PhabricatorObjectHasSubscriberEdgeType::EDGECONST; 862 - 863 - $edges = id(new PhabricatorEdgeQuery()) 864 - ->withSourcePHIDs(mpull($revisions, 'getPHID')) 865 - ->withEdgeTypes(array($type_reviewer, $type_subscriber)) 866 - ->setOrder(PhabricatorEdgeQuery::ORDER_OLDEST_FIRST) 867 - ->execute(); 868 - 869 - $type_map = array( 870 - DifferentialRevision::RELATION_REVIEWER => $type_reviewer, 871 - DifferentialRevision::RELATION_SUBSCRIBED => $type_subscriber, 872 - ); 873 - 874 - foreach ($revisions as $revision) { 875 - $data = array(); 876 - foreach ($type_map as $rel_type => $edge_type) { 877 - $revision_edges = $edges[$revision->getPHID()][$edge_type]; 878 - foreach ($revision_edges as $dst_phid => $edge_data) { 879 - $data[] = array( 880 - 'relation' => $rel_type, 881 - 'objectPHID' => $dst_phid, 882 - 'reasonPHID' => null, 883 - ); 884 - } 885 - } 886 - 887 - $revision->attachRelationships($data); 888 - } 889 836 } 890 837 891 838 private function loadCommitPHIDs($conn_r, array $revisions) {
-1
src/applications/differential/query/DifferentialRevisionSearchEngine.php
··· 19 19 return id(new DifferentialRevisionQuery()) 20 20 ->needFlags(true) 21 21 ->needDrafts(true) 22 - ->needRelationships(true) 23 22 ->needReviewerStatus(true); 24 23 } 25 24
+5 -60
src/applications/differential/storage/DifferentialRevision.php
··· 38 38 protected $editPolicy = PhabricatorPolicies::POLICY_USER; 39 39 protected $properties = array(); 40 40 41 - private $relationships = self::ATTACHABLE; 42 41 private $commits = self::ATTACHABLE; 43 42 private $activeDiff = self::ATTACHABLE; 44 43 private $diffIDs = self::ATTACHABLE; ··· 69 68 return id(new DifferentialRevision()) 70 69 ->setViewPolicy($view_policy) 71 70 ->setAuthorPHID($actor->getPHID()) 72 - ->attachRelationships(array()) 73 71 ->attachRepository(null) 74 72 ->attachActiveDiff(null) 75 73 ->attachReviewerStatus(array()) ··· 238 236 return parent::save(); 239 237 } 240 238 241 - public function loadRelationships() { 242 - if (!$this->getID()) { 243 - $this->relationships = array(); 244 - return; 245 - } 246 - 247 - $data = array(); 248 - 249 - $subscriber_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 250 - $this->getPHID(), 251 - PhabricatorObjectHasSubscriberEdgeType::EDGECONST); 252 - $subscriber_phids = array_reverse($subscriber_phids); 253 - foreach ($subscriber_phids as $phid) { 254 - $data[] = array( 255 - 'relation' => self::RELATION_SUBSCRIBED, 256 - 'objectPHID' => $phid, 257 - 'reasonPHID' => null, 258 - ); 259 - } 260 - 261 - $reviewer_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 262 - $this->getPHID(), 263 - DifferentialRevisionHasReviewerEdgeType::EDGECONST); 264 - $reviewer_phids = array_reverse($reviewer_phids); 265 - foreach ($reviewer_phids as $phid) { 266 - $data[] = array( 267 - 'relation' => self::RELATION_REVIEWER, 268 - 'objectPHID' => $phid, 269 - 'reasonPHID' => null, 270 - ); 271 - } 272 - 273 - return $this->attachRelationships($data); 274 - } 275 - 276 - public function attachRelationships(array $relationships) { 277 - $this->relationships = igroup($relationships, 'relation'); 278 - return $this; 279 - } 280 - 281 - public function getReviewers() { 282 - return $this->getRelatedPHIDs(self::RELATION_REVIEWER); 283 - } 284 - 285 - public function getCCPHIDs() { 286 - return $this->getRelatedPHIDs(self::RELATION_SUBSCRIBED); 287 - } 288 - 289 - private function getRelatedPHIDs($relation) { 290 - $this->assertAttached($this->relationships); 291 - 292 - return ipull($this->getRawRelations($relation), 'objectPHID'); 293 - } 294 - 295 - public function getRawRelations($relation) { 296 - return idx($this->relationships, $relation, array()); 297 - } 298 - 299 239 public function getHashes() { 300 240 return $this->assertAttached($this->hashes); 301 241 } ··· 400 340 assert_instances_of($reviewers, 'DifferentialReviewer'); 401 341 $this->reviewerStatus = $reviewers; 402 342 return $this; 343 + } 344 + 345 + public function getReviewerPHIDs() { 346 + $reviewers = $this->getReviewerStatus(); 347 + return mpull($reviewers, 'getReviewerPHID'); 403 348 } 404 349 405 350 public function getReviewerPHIDsForEdit() {
+2 -6
src/applications/differential/view/DifferentialRevisionListView.php
··· 52 52 $phids = array(); 53 53 foreach ($this->revisions as $revision) { 54 54 $phids[] = array($revision->getAuthorPHID()); 55 - 56 - // TODO: Switch to getReviewerStatus(), but not all callers pass us 57 - // revisions with this data loaded. 58 - $phids[] = $revision->getReviewers(); 55 + $phids[] = $revision->getReviewerPHIDs(); 59 56 } 60 57 return array_mergev($phids); 61 58 } ··· 132 129 } 133 130 134 131 $reviewers = array(); 135 - // TODO: As above, this should be based on `getReviewerStatus()`. 136 - foreach ($revision->getReviewers() as $reviewer) { 132 + foreach ($revision->getReviewerPHIDs() as $reviewer) { 137 133 $reviewers[] = $this->handles[$reviewer]->renderLink(); 138 134 } 139 135 if (!$reviewers) {
+1 -1
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 1765 1765 ->withUpdatedEpochBetween($recent, null) 1766 1766 ->setOrder(DifferentialRevisionQuery::ORDER_MODIFIED) 1767 1767 ->setLimit(10) 1768 - ->needRelationships(true) 1768 + ->needReviewerStatus(true) 1769 1769 ->needFlags(true) 1770 1770 ->needDrafts(true) 1771 1771 ->execute();
+1 -1
src/applications/diffusion/herald/DiffusionCommitRevisionReviewersHeraldField.php
··· 20 20 return array(); 21 21 } 22 22 23 - return $revision->getReviewers(); 23 + return $revision->getReviewerPHIDs(); 24 24 } 25 25 26 26 protected function getHeraldFieldStandardType() {
+2 -2
src/applications/diffusion/herald/DiffusionPreCommitContentRevisionReviewersHeraldField.php
··· 20 20 return array(); 21 21 } 22 22 23 - return $revision->getReviewers(); 24 - } 23 + return $revision->getReviewerPHIDs(); 24 + } 25 25 26 26 protected function getHeraldFieldStandardType() { 27 27 return self::STANDARD_PHID_LIST;
-1
src/applications/diffusion/herald/HeraldCommitAdapter.php
··· 190 190 $revision = id(new DifferentialRevisionQuery()) 191 191 ->withIDs(array($revision_id)) 192 192 ->setViewer(PhabricatorUser::getOmnipotentUser()) 193 - ->needRelationships(true) 194 193 ->needReviewerStatus(true) 195 194 ->executeOne(); 196 195 if ($revision) {
+1 -1
src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
··· 190 190 $this->revision = id(new DifferentialRevisionQuery()) 191 191 ->setViewer(PhabricatorUser::getOmnipotentUser()) 192 192 ->withIDs(array($revision_id)) 193 - ->needRelationships(true) 193 + ->needReviewerStatus(true) 194 194 ->executeOne(); 195 195 } 196 196 }