mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Use PhabricatorCachedClassMapQuery when querying object PHID types
Summary: Ref T11954. When we query for Conduit tokens, we load the associated objects (users) by PHID. Currently, querying objects by PHID requires us to load every PHIDType class, when we can know which specific classes we actually need (e.g., just `UserPHIDType`, if only user PHIDs are present in the query). Use PhabricatorCachedClassMapQuery to reduce the number of classes we load on this pathway. Test Plan: - Used `ab -n100` to roughly measure a ~5% performance improvement? - This measurement feels a little flimsy but the XHProf profile is cleaner, at least. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11954 Differential Revision: https://secure.phabricator.com/D16997
This commit is contained in:
parent
bfbf75a872
commit
f8d6b6181e
2 changed files with 30 additions and 9 deletions
|
@ -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();
|
||||
|
|
|
@ -144,10 +144,21 @@ abstract class PhabricatorPHIDType extends Phobject {
|
|||
* @return dict<string, PhabricatorPHIDType> 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');
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue