1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

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
This commit is contained in:
epriestley 2019-04-22 11:42:38 -07:00
parent 70c643c685
commit fc92cf4382

View file

@ -36,27 +36,7 @@ final class DiffusionBlameController extends DiffusionController {
$commit_map = mpull($commits, 'getCommitIdentifier', 'getPHID'); $commit_map = mpull($commits, 'getCommitIdentifier', 'getPHID');
$revisions = array(); $revision_map = $this->loadRevisionsForCommits($commits);
$revision_map = array();
if ($commits) {
$revision_ids = id(new DifferentialRevision())
->loadIDsByCommitPHIDs(array_keys($commit_map));
if ($revision_ids) {
$revisions = id(new DifferentialRevisionQuery())
->setViewer($viewer)
->withIDs($revision_ids)
->execute();
$revisions = mpull($revisions, null, 'getID');
}
foreach ($revision_ids as $commit_phid => $revision_id) {
// If the viewer can't actually see this revision, skip it.
if (!isset($revisions[$revision_id])) {
continue;
}
$revision_map[$commit_map[$commit_phid]] = $revision_id;
}
}
$base_href = (string)$drequest->generateURI( $base_href = (string)$drequest->generateURI(
array( array(
@ -75,8 +55,10 @@ final class DiffusionBlameController extends DiffusionController {
$handle_phids[] = $commit->getAuthorDisplayPHID(); $handle_phids[] = $commit->getAuthorDisplayPHID();
} }
foreach ($revisions as $revision) { foreach ($revision_map as $revisions) {
$handle_phids[] = $revision->getAuthorPHID(); foreach ($revisions as $revision) {
$handle_phids[] = $revision->getAuthorPHID();
}
} }
$handles = $viewer->loadHandles($handle_phids); $handles = $viewer->loadHandles($handle_phids);
@ -84,13 +66,6 @@ final class DiffusionBlameController extends DiffusionController {
$map = array(); $map = array();
$epochs = array(); $epochs = array();
foreach ($identifiers as $identifier) { foreach ($identifiers as $identifier) {
$revision_id = idx($revision_map, $identifier);
if ($revision_id) {
$revision = idx($revisions, $revision_id);
} else {
$revision = null;
}
$skip_href = $base_href.'?before='.$identifier; $skip_href = $base_href.'?before='.$identifier;
$skip_link = javelin_tag( $skip_link = javelin_tag(
@ -115,6 +90,17 @@ final class DiffusionBlameController extends DiffusionController {
$commit = idx($commits, $identifier); $commit = idx($commits, $identifier);
$revision = null;
if ($commit) {
$revisions = idx($revision_map, $commit->getPHID());
// There may be multiple edges between this commit and revisions in the
// database. If there are, just pick one arbitrarily.
if ($revisions) {
$revision = head($revisions);
}
}
$author_phid = null; $author_phid = null;
if ($commit) { if ($commit) {
@ -281,4 +267,45 @@ final class DiffusionBlameController extends DiffusionController {
} }
} }
private function loadRevisionsForCommits(array $commits) {
if (!$commits) {
return array();
}
$commit_phids = mpull($commits, 'getPHID');
$edge_query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($commit_phids)
->withEdgeTypes(
array(
DiffusionCommitHasRevisionEdgeType::EDGECONST,
));
$edge_query->execute();
$revision_phids = $edge_query->getDestinationPHIDs();
if (!$revision_phids) {
return array();
}
$viewer = $this->getViewer();
$revisions = id(new DifferentialRevisionQuery())
->setViewer($viewer)
->withPHIDs($revision_phids)
->execute();
$revisions = mpull($revisions, null, 'getPHID');
$map = array();
foreach ($commit_phids as $commit_phid) {
$revision_phids = $edge_query->getDestinationPHIDs(
array(
$commit_phid,
));
$map[$commit_phid] = array_select_keys($revisions, $revision_phids);
}
return $map;
}
} }