1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 08:12:40 +01:00

Add a debug view of the "Affected Path" index to Differential

Summary:
Ref T13639. The "Affected Path" table is currently hard to inspect: there's no UI, and using MySQL just gives you a bunch of IDs.

Add a simple UI and a debug-mode link to it.

Test Plan:
{F8539098}

{F8539099}

Maniphest Tasks: T13639

Differential Revision: https://secure.phabricator.com/D21615
This commit is contained in:
epriestley 2021-03-15 13:41:37 -07:00
parent c317d16bdd
commit e919b4c35a
4 changed files with 141 additions and 0 deletions

View file

@ -613,6 +613,7 @@ phutil_register_library_map(array(
'DifferentialRevisionAcceptTransaction' => 'applications/differential/xaction/DifferentialRevisionAcceptTransaction.php', 'DifferentialRevisionAcceptTransaction' => 'applications/differential/xaction/DifferentialRevisionAcceptTransaction.php',
'DifferentialRevisionActionTransaction' => 'applications/differential/xaction/DifferentialRevisionActionTransaction.php', 'DifferentialRevisionActionTransaction' => 'applications/differential/xaction/DifferentialRevisionActionTransaction.php',
'DifferentialRevisionAffectedFilesHeraldField' => 'applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php', 'DifferentialRevisionAffectedFilesHeraldField' => 'applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php',
'DifferentialRevisionAffectedPathsController' => 'applications/differential/controller/DifferentialRevisionAffectedPathsController.php',
'DifferentialRevisionAuthorHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorHeraldField.php', 'DifferentialRevisionAuthorHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorHeraldField.php',
'DifferentialRevisionAuthorPackagesHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorPackagesHeraldField.php', 'DifferentialRevisionAuthorPackagesHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorPackagesHeraldField.php',
'DifferentialRevisionAuthorProjectsHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php', 'DifferentialRevisionAuthorProjectsHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php',
@ -6733,6 +6734,7 @@ phutil_register_library_map(array(
'DifferentialRevisionAcceptTransaction' => 'DifferentialRevisionReviewTransaction', 'DifferentialRevisionAcceptTransaction' => 'DifferentialRevisionReviewTransaction',
'DifferentialRevisionActionTransaction' => 'DifferentialRevisionTransactionType', 'DifferentialRevisionActionTransaction' => 'DifferentialRevisionTransactionType',
'DifferentialRevisionAffectedFilesHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionAffectedFilesHeraldField' => 'DifferentialRevisionHeraldField',
'DifferentialRevisionAffectedPathsController' => 'DifferentialController',
'DifferentialRevisionAuthorHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionAuthorHeraldField' => 'DifferentialRevisionHeraldField',
'DifferentialRevisionAuthorPackagesHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionAuthorPackagesHeraldField' => 'DifferentialRevisionHeraldField',
'DifferentialRevisionAuthorProjectsHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionAuthorProjectsHeraldField' => 'DifferentialRevisionHeraldField',

View file

@ -74,6 +74,8 @@ final class PhabricatorDifferentialApplication
=> 'DifferentialRevisionOperationController', => 'DifferentialRevisionOperationController',
'inlines/(?P<id>[1-9]\d*)/' 'inlines/(?P<id>[1-9]\d*)/'
=> 'DifferentialRevisionInlinesController', => 'DifferentialRevisionInlinesController',
'paths/(?P<id>[1-9]\d*)/'
=> 'DifferentialRevisionAffectedPathsController',
), ),
'comment/' => array( 'comment/' => array(
'inline/' => array( 'inline/' => array(

View file

@ -0,0 +1,127 @@
<?php
final class DifferentialRevisionAffectedPathsController
extends DifferentialController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
$revision = id(new DifferentialRevisionQuery())
->withIDs(array($id))
->setViewer($viewer)
->executeOne();
if (!$revision) {
return new Aphront404Response();
}
$table = new DifferentialAffectedPath();
$conn = $table->establishConnection('r');
$paths = queryfx_all(
$conn,
'SELECT * FROM %R WHERE revisionID = %d',
$table,
$revision->getID());
$repository_ids = array();
$path_ids = array();
foreach ($paths as $path) {
$repository_id = $path['repositoryID'];
$path_id = $path['pathID'];
$repository_ids[] = $repository_id;
$path_ids[] = $path_id;
}
$repository_ids = array_fuse($repository_ids);
if ($repository_ids) {
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withIDs($repository_ids)
->execute();
$repositories = mpull($repositories, null, 'getID');
} else {
$repositories = array();
}
$handles = $viewer->loadHandles(mpull($repositories, 'getPHID'));
$path_ids = array_fuse($path_ids);
if ($path_ids) {
$path_names = id(new DiffusionPathQuery())
->withPathIDs($path_ids)
->execute();
} else {
$path_names = array();
}
$rows = array();
foreach ($paths as $path) {
$repository_id = $path['repositoryID'];
$path_id = $path['pathID'];
$repository = idx($repositories, $repository_id);
if ($repository) {
$repository_phid = $repository->getPHID();
$repository_link = $handles[$repository_phid]->renderLink();
} else {
$repository_link = null;
}
$path_name = idx($path_names, $path_id);
if ($path_name !== null) {
$path_view = $path_name['path'];
} else {
$path_view = null;
}
$rows[] = array(
$repository_id,
$repository_link,
$path_id,
$path_view,
);
}
// Sort rows by path name.
$rows = isort($rows, 3);
$table_view = id(new AphrontTableView($rows))
->setNoDataString(pht('This revision has no indexed affected paths.'))
->setHeaders(
array(
pht('Repository ID'),
pht('Repository'),
pht('Path ID'),
pht('Path'),
))
->setColumnClasses(
array(
null,
null,
null,
'wide',
));
$box_view = id(new PHUIObjectBoxView())
->setHeaderText(pht('Affected Path Index'))
->setTable($table_view);
$crumbs = $this->buildApplicationCrumbs()
->addTextCrumb($revision->getMonogram(), $revision->getURI())
->addTextCrumb(pht('Affected Path Index'));
return $this->newPage()
->setCrumbs($crumbs)
->setTitle(
array(
$revision->getMonogram(),
pht('Affected Path Index'),
))
->appendChild($box_view);
}
}

View file

@ -44,6 +44,16 @@ final class PhabricatorSystemDebugUIEventListener
->setName(pht('View Hovercard')) ->setName(pht('View Hovercard'))
->setHref(urisprintf('/search/hovercard/?names=%s', $phid)); ->setHref(urisprintf('/search/hovercard/?names=%s', $phid));
if ($object instanceof DifferentialRevision) {
$submenu[] = id(new PhabricatorActionView())
->setIcon('fa-database')
->setName(pht('View Affected Path Index'))
->setHref(
urisprintf(
'/differential/revision/paths/%s/',
$object->getID()));
}
$developer_action = id(new PhabricatorActionView()) $developer_action = id(new PhabricatorActionView())
->setName(pht('Advanced/Developer...')) ->setName(pht('Advanced/Developer...'))
->setIcon('fa-magic') ->setIcon('fa-magic')