diff --git a/src/applications/phid/query/PhabricatorObjectQuery.php b/src/applications/phid/query/PhabricatorObjectQuery.php --- a/src/applications/phid/query/PhabricatorObjectQuery.php +++ b/src/applications/phid/query/PhabricatorObjectQuery.php @@ -29,11 +29,6 @@ $this->namedResults = array(); } - $types = PhabricatorPHIDType::getAllTypes(); - if ($this->types) { - $types = array_select_keys($types, $this->types); - } - $names = array_unique($this->names); $phids = $this->phids; @@ -51,15 +46,30 @@ } } - $phids = array_unique($phids); - if ($names) { + $types = PhabricatorPHIDType::getAllTypes(); + if ($this->types) { + $types = array_select_keys($types, $this->types); + } $name_results = $this->loadObjectsByName($types, $names); } else { $name_results = array(); } if ($phids) { + $phids = array_unique($phids); + + $phid_types = array(); + foreach ($phids as $phid) { + $phid_type = phid_get_type($phid); + $phid_types[$phid_type] = $phid_type; + } + + $types = PhabricatorPHIDType::getTypes($phid_types); + if ($this->types) { + $types = array_select_keys($types, $this->types); + } + $phid_results = $this->loadObjectsByPHID($types, $phids); } else { $phid_results = array(); diff --git a/src/applications/phid/type/PhabricatorPHIDType.php b/src/applications/phid/type/PhabricatorPHIDType.php --- a/src/applications/phid/type/PhabricatorPHIDType.php +++ b/src/applications/phid/type/PhabricatorPHIDType.php @@ -144,10 +144,21 @@ * @return dict Map of type constants to types. */ final public static function getAllTypes() { + return self::newClassMapQuery() + ->execute(); + } + + final public static function getTypes(array $types) { + return id(new PhabricatorCachedClassMapQuery()) + ->setClassMapQuery(self::newClassMapQuery()) + ->setMapKeyMethod('getTypeConstant') + ->loadClasses($types); + } + + private static function newClassMapQuery() { return id(new PhutilClassMapQuery()) ->setAncestorClass(__CLASS__) - ->setUniqueMethod('getTypeConstant') - ->execute(); + ->setUniqueMethod('getTypeConstant'); }