diff --git a/src/applications/phid/query/PhabricatorObjectQuery.php b/src/applications/phid/query/PhabricatorObjectQuery.php index 65e9938311..8364f0210d 100644 --- a/src/applications/phid/query/PhabricatorObjectQuery.php +++ b/src/applications/phid/query/PhabricatorObjectQuery.php @@ -29,11 +29,6 @@ final class PhabricatorObjectQuery $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 @@ final class PhabricatorObjectQuery } } - $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 index 99deb84763..2f82dcf169 100644 --- a/src/applications/phid/type/PhabricatorPHIDType.php +++ b/src/applications/phid/type/PhabricatorPHIDType.php @@ -144,10 +144,21 @@ abstract class PhabricatorPHIDType extends Phobject { * @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'); }