diff --git a/src/applications/differential/query/DifferentialRevisionQuery.php b/src/applications/differential/query/DifferentialRevisionQuery.php --- a/src/applications/differential/query/DifferentialRevisionQuery.php +++ b/src/applications/differential/query/DifferentialRevisionQuery.php @@ -466,13 +466,25 @@ $basic_authors = $this->authors; $basic_reviewers = $this->reviewers; + // Note that '$this->responsibles' can contain both projects and users, + // so let's get only the users. + $responsible_users = $this->filterUserPHIDs($this->responsibles); + try { + // First part of the UNION query: // Build the query where the responsible users are authors. - $this->authors = array_merge($basic_authors, $this->responsibles); - + // Special case: skip this first query if it does not have any + // condition, because it would just return everything, + // and we would generate "(SELECT EVERYTHING) UNION (SELECT SOMETHING)" + // and this first nonsense query returning everything would defuse the + // next query returning something. + $this->authors = array_merge($basic_authors, $responsible_users); $this->reviewers = $basic_reviewers; - $selects[] = $this->buildSelectStatement($conn); + if (!$this->authors && !$this->reviewers) { + $selects[] = $this->buildSelectStatement($conn); + } + // Second part of the UNION query: // Build the query where the responsible users are reviewers, or // projects they are members of are reviewers. $this->authors = $basic_authors; @@ -1080,6 +1092,16 @@ return $user_authority + $project_authority + $package_authority; } + /** + * Get a list of PHIDs, and return only user PHIDs. + * @param array $phids Mixed PHIDs + * @return array PHIDs User PHIDs + */ + private function filterUserPHIDs(array $phids): array { + $phids_grouped = phid_group_by_type($phids); + return idx($phids_grouped, PhabricatorPeopleUserPHIDType::TYPECONST, []); + } + public function getQueryApplicationClass() { return PhabricatorDifferentialApplication::class; }