1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

Clean up ProjectQuery when viewer is logged-out or omnipotent

Summary:
Ref T10010. When the viewer is logged-out or omnipotent, we can skip this query.

(Currently we issue a silly query like `src = X AND type = Y AND dst = ''`, which will never return results.)

Test Plan:
  - Viewed projects as normal user and logged-out user.
  - Ran unit tests.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10010

Differential Revision: https://secure.phabricator.com/D14892
This commit is contained in:
epriestley 2015-12-27 04:15:39 -08:00
parent 2b5d4bca8a
commit 77897ce862

View file

@ -226,11 +226,21 @@ final class PhabricatorProjectQuery
// If we only need to know if the viewer is a member, we can restrict // If we only need to know if the viewer is a member, we can restrict
// the query to just their PHID. // the query to just their PHID.
$any_edges = true;
if (!$this->needMembers && !$this->needWatchers) { if (!$this->needMembers && !$this->needWatchers) {
if ($viewer_phid) {
$edge_query->withDestinationPHIDs(array($viewer_phid)); $edge_query->withDestinationPHIDs(array($viewer_phid));
} else {
// If we don't need members or watchers and don't have a viewer PHID
// (viewer is logged-out or omnipotent), they'll never be a member
// so we don't need to issue this query at all.
$any_edges = false;
}
} }
if ($any_edges) {
$edge_query->execute(); $edge_query->execute();
}
$membership_projects = array(); $membership_projects = array();
foreach ($projects as $project) { foreach ($projects as $project) {
@ -242,9 +252,13 @@ final class PhabricatorProjectQuery
$source_phids = array($project_phid); $source_phids = array($project_phid);
} }
if ($any_edges) {
$member_phids = $edge_query->getDestinationPHIDs( $member_phids = $edge_query->getDestinationPHIDs(
$source_phids, $source_phids,
array($member_type)); array($member_type));
} else {
$member_phids = array();
}
if (in_array($viewer_phid, $member_phids)) { if (in_array($viewer_phid, $member_phids)) {
$membership_projects[$project_phid] = $project; $membership_projects[$project_phid] = $project;