From f8af89a99efcb0ada2ef6582b7e9e31d5119cd4a Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 14 Aug 2014 13:04:38 -0700 Subject: [PATCH] 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 --- .../query/PhabricatorCommitSearchEngine.php | 3 -- .../diffusion/query/DiffusionCommitQuery.php | 29 ++++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/applications/audit/query/PhabricatorCommitSearchEngine.php b/src/applications/audit/query/PhabricatorCommitSearchEngine.php index 3d86c9b76c..4cd9e3018f 100644 --- a/src/applications/audit/query/PhabricatorCommitSearchEngine.php +++ b/src/applications/audit/query/PhabricatorCommitSearchEngine.php @@ -61,9 +61,6 @@ final class PhabricatorCommitSearchEngine $repository_phids = $saved->getParameter('repositoryPHIDs', array()); if ($repository_phids) { - // $repository_phids need to be mapped to $repository_ids via a subquery - // so make sure $viewer is set...! - $query->setViewer($this->requireViewer()); $query->withRepositoryPHIDs($repository_phids); } diff --git a/src/applications/diffusion/query/DiffusionCommitQuery.php b/src/applications/diffusion/query/DiffusionCommitQuery.php index a472691ce4..a565986198 100644 --- a/src/applications/diffusion/query/DiffusionCommitQuery.php +++ b/src/applications/diffusion/query/DiffusionCommitQuery.php @@ -9,6 +9,7 @@ final class DiffusionCommitQuery private $defaultRepository; private $identifiers; private $repositoryIDs; + private $repositoryPHIDs; private $identifierMap; private $needAuditRequests; @@ -63,19 +64,9 @@ final class DiffusionCommitQuery * Look up commits in a specific repository. Prefer * @{method:withRepositoryIDs}; the underyling table is keyed by ID such * that this method requires a separate initial query to map PHID to ID. - * Furthermore, this method requires calling @{method:setViewer} in - * advance due to the separate query. */ public function withRepositoryPHIDs(array $phids) { - $repositories = id (new PhabricatorRepositoryQuery()) - ->setViewer($this->getViewer()) - ->withPHIDs($phids) - ->execute(); - - if (!$repositories) { - throw new PhabricatorEmptyQueryException(); - } - $this->withRepositoryIDs(mpull($repositories, 'getID')); + $this->repositoryPHIDs = $phids; } /** @@ -282,6 +273,22 @@ final class DiffusionCommitQuery private function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); + if ($this->repositoryPHIDs !== null) { + $map_repositories = id (new PhabricatorRepositoryQuery()) + ->setViewer($this->getViewer()) + ->withPHIDs($this->repositoryPHIDs) + ->execute(); + + if (!$map_repositories) { + throw new PhabricatorEmptyQueryException(); + } + $repository_ids = mpull($map_repositories, 'getID'); + if ($this->repositoryIDs !== null) { + $repository_ids = array_merge($repository_ids, $this->repositoryIDs); + } + $this->withRepositoryIDs($repository_ids); + } + if ($this->ids !== null) { $where[] = qsprintf( $conn_r,