From 77897ce862580f1b06d067db8425d78a50a7dca6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 27 Dec 2015 04:15:39 -0800 Subject: [PATCH] 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 --- .../project/query/PhabricatorProjectQuery.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index 02d4474777..11a789ab31 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -226,11 +226,21 @@ final class PhabricatorProjectQuery // If we only need to know if the viewer is a member, we can restrict // the query to just their PHID. + $any_edges = true; if (!$this->needMembers && !$this->needWatchers) { - $edge_query->withDestinationPHIDs(array($viewer_phid)); + if ($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; + } } - $edge_query->execute(); + if ($any_edges) { + $edge_query->execute(); + } $membership_projects = array(); foreach ($projects as $project) { @@ -242,9 +252,13 @@ final class PhabricatorProjectQuery $source_phids = array($project_phid); } - $member_phids = $edge_query->getDestinationPHIDs( - $source_phids, - array($member_type)); + if ($any_edges) { + $member_phids = $edge_query->getDestinationPHIDs( + $source_phids, + array($member_type)); + } else { + $member_phids = array(); + } if (in_array($viewer_phid, $member_phids)) { $membership_projects[$project_phid] = $project;