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

Move BlameController away from ancient "TABLE_COMMIT"

Summary:
Ref T13276. Differential has a pre-edge "TABLE_COMMIT" with about a half-dozen weird callers I'd like to get rid of.

Move blame to use edges instead. (Bonus: this makes blame respect edge edits in the UI.)

Since there are some more callers to clean up this code may move into some "RelatedObjectQueryThing" class or something, but I'm taking it one step at a time for now.

Test Plan: {F6394106}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13276

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

+57 -30
+57 -30
src/applications/diffusion/controller/DiffusionBlameController.php
··· 36 36 37 37 $commit_map = mpull($commits, 'getCommitIdentifier', 'getPHID'); 38 38 39 - $revisions = array(); 40 - $revision_map = array(); 41 - if ($commits) { 42 - $revision_ids = id(new DifferentialRevision()) 43 - ->loadIDsByCommitPHIDs(array_keys($commit_map)); 44 - if ($revision_ids) { 45 - $revisions = id(new DifferentialRevisionQuery()) 46 - ->setViewer($viewer) 47 - ->withIDs($revision_ids) 48 - ->execute(); 49 - $revisions = mpull($revisions, null, 'getID'); 50 - } 51 - 52 - foreach ($revision_ids as $commit_phid => $revision_id) { 53 - // If the viewer can't actually see this revision, skip it. 54 - if (!isset($revisions[$revision_id])) { 55 - continue; 56 - } 57 - $revision_map[$commit_map[$commit_phid]] = $revision_id; 58 - } 59 - } 39 + $revision_map = $this->loadRevisionsForCommits($commits); 60 40 61 41 $base_href = (string)$drequest->generateURI( 62 42 array( ··· 75 55 $handle_phids[] = $commit->getAuthorDisplayPHID(); 76 56 } 77 57 78 - foreach ($revisions as $revision) { 79 - $handle_phids[] = $revision->getAuthorPHID(); 58 + foreach ($revision_map as $revisions) { 59 + foreach ($revisions as $revision) { 60 + $handle_phids[] = $revision->getAuthorPHID(); 61 + } 80 62 } 81 63 82 64 $handles = $viewer->loadHandles($handle_phids); ··· 84 66 $map = array(); 85 67 $epochs = array(); 86 68 foreach ($identifiers as $identifier) { 87 - $revision_id = idx($revision_map, $identifier); 88 - if ($revision_id) { 89 - $revision = idx($revisions, $revision_id); 90 - } else { 91 - $revision = null; 92 - } 93 - 94 69 $skip_href = $base_href.'?before='.$identifier; 95 70 96 71 $skip_link = javelin_tag( ··· 114 89 // doesn't correspond to a real commit. 115 90 116 91 $commit = idx($commits, $identifier); 92 + 93 + $revision = null; 94 + if ($commit) { 95 + $revisions = idx($revision_map, $commit->getPHID()); 96 + 97 + // There may be multiple edges between this commit and revisions in the 98 + // database. If there are, just pick one arbitrarily. 99 + if ($revisions) { 100 + $revision = head($revisions); 101 + } 102 + } 117 103 118 104 $author_phid = null; 119 105 ··· 279 265 } else { 280 266 return "{$summary}\n{$date}"; 281 267 } 268 + } 269 + 270 + private function loadRevisionsForCommits(array $commits) { 271 + if (!$commits) { 272 + return array(); 273 + } 274 + 275 + $commit_phids = mpull($commits, 'getPHID'); 276 + 277 + $edge_query = id(new PhabricatorEdgeQuery()) 278 + ->withSourcePHIDs($commit_phids) 279 + ->withEdgeTypes( 280 + array( 281 + DiffusionCommitHasRevisionEdgeType::EDGECONST, 282 + )); 283 + $edge_query->execute(); 284 + 285 + $revision_phids = $edge_query->getDestinationPHIDs(); 286 + if (!$revision_phids) { 287 + return array(); 288 + } 289 + 290 + $viewer = $this->getViewer(); 291 + 292 + $revisions = id(new DifferentialRevisionQuery()) 293 + ->setViewer($viewer) 294 + ->withPHIDs($revision_phids) 295 + ->execute(); 296 + $revisions = mpull($revisions, null, 'getPHID'); 297 + 298 + $map = array(); 299 + foreach ($commit_phids as $commit_phid) { 300 + $revision_phids = $edge_query->getDestinationPHIDs( 301 + array( 302 + $commit_phid, 303 + )); 304 + 305 + $map[$commit_phid] = array_select_keys($revisions, $revision_phids); 306 + } 307 + 308 + return $map; 282 309 } 283 310 284 311 }