From d923f68aad2af62ca872a1243ff6cf44708157aa Mon Sep 17 00:00:00 2001 From: Fabian Stelzer Date: Tue, 2 Dec 2014 05:51:46 -0800 Subject: [PATCH] performance optimazion for edge queries with getDestinationPHIDs Summary: Ref T6656 performance optimazion for edge queries with getDestinationPHIDs Test Plan: accessed reports and several pages containing tasks with edges (projects...) Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T6656 Differential Revision: https://secure.phabricator.com/D10916 --- .../edges/query/PhabricatorEdgeQuery.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/infrastructure/edges/query/PhabricatorEdgeQuery.php b/src/infrastructure/edges/query/PhabricatorEdgeQuery.php index 976a35b9ae..17f1660b33 100644 --- a/src/infrastructure/edges/query/PhabricatorEdgeQuery.php +++ b/src/infrastructure/edges/query/PhabricatorEdgeQuery.php @@ -260,20 +260,21 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery { 'You must execute() a query before you you can getDestinationPHIDs().'); } - $src_phids = array_fill_keys($src_phids, true); - $types = array_fill_keys($types, true); - $result_phids = array(); - foreach ($this->resultSet as $src => $edges_by_type) { - if ($src_phids && empty($src_phids[$src])) { - continue; + + $set = $this->resultSet; + if ($src_phids) { + $set = array_select_keys($set, $src_phids); + } + + foreach ($set as $src => $edges_by_type) { + if ($types) { + $edges_by_type = array_select_keys($edges_by_type, $types); } - foreach ($edges_by_type as $type => $edges_by_dst) { - if ($types && empty($types[$type])) { - continue; - } - foreach ($edges_by_dst as $dst => $edge) { - $result_phids[$dst] = true; + + foreach ($edges_by_type as $edges) { + foreach ($edges as $edge_phid => $edge) { + $result_phids[$edge_phid] = true; } } }