Skip to content

Commit f8af89a

Browse files
committed
DiffusionCommitQuery - move phid to id mapping
Summary: Ref T5862. makes the exception work better Test Plan: issued some queries from audit ui with and without repos - they worked Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T5862 Differential Revision: https://secure.phabricator.com/D10268
1 parent 644e950 commit f8af89a

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/applications/audit/query/PhabricatorCommitSearchEngine.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
6161

6262
$repository_phids = $saved->getParameter('repositoryPHIDs', array());
6363
if ($repository_phids) {
64-
// $repository_phids need to be mapped to $repository_ids via a subquery
65-
// so make sure $viewer is set...!
66-
$query->setViewer($this->requireViewer());
6764
$query->withRepositoryPHIDs($repository_phids);
6865
}
6966

src/applications/diffusion/query/DiffusionCommitQuery.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ final class DiffusionCommitQuery
99
private $defaultRepository;
1010
private $identifiers;
1111
private $repositoryIDs;
12+
private $repositoryPHIDs;
1213
private $identifierMap;
1314

1415
private $needAuditRequests;
@@ -63,19 +64,9 @@ public function withRepository(PhabricatorRepository $repository) {
6364
* Look up commits in a specific repository. Prefer
6465
* @{method:withRepositoryIDs}; the underyling table is keyed by ID such
6566
* that this method requires a separate initial query to map PHID to ID.
66-
* Furthermore, this method requires calling @{method:setViewer} in
67-
* advance due to the separate query.
6867
*/
6968
public function withRepositoryPHIDs(array $phids) {
70-
$repositories = id (new PhabricatorRepositoryQuery())
71-
->setViewer($this->getViewer())
72-
->withPHIDs($phids)
73-
->execute();
74-
75-
if (!$repositories) {
76-
throw new PhabricatorEmptyQueryException();
77-
}
78-
$this->withRepositoryIDs(mpull($repositories, 'getID'));
69+
$this->repositoryPHIDs = $phids;
7970
}
8071

8172
/**
@@ -282,6 +273,22 @@ protected function didFilterPage(array $commits) {
282273
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
283274
$where = array();
284275

276+
if ($this->repositoryPHIDs !== null) {
277+
$map_repositories = id (new PhabricatorRepositoryQuery())
278+
->setViewer($this->getViewer())
279+
->withPHIDs($this->repositoryPHIDs)
280+
->execute();
281+
282+
if (!$map_repositories) {
283+
throw new PhabricatorEmptyQueryException();
284+
}
285+
$repository_ids = mpull($map_repositories, 'getID');
286+
if ($this->repositoryIDs !== null) {
287+
$repository_ids = array_merge($repository_ids, $this->repositoryIDs);
288+
}
289+
$this->withRepositoryIDs($repository_ids);
290+
}
291+
285292
if ($this->ids !== null) {
286293
$where[] = qsprintf(
287294
$conn_r,

0 commit comments

Comments
 (0)