mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Improve performance when constructing custom fields for objects
Summary: Ref T11404. This improves things by about 10%: - Use `PhutilClassMapQuery`, which has slightly better caching. - Do a little less work to generate pretty error messages. - Make the "disabled" code a little faster (and sort of clearer, too?) by doing less fancy stuff. These are pretty minor adjustments and not the sort of optimizations I'd make normally, but this code gets called ~100x (once per revision) and generates ~10 fields normally, so even small savings can amount to something. (I also want to try to make `arc` faster in the next update, and improving Conduit performance helps with that.) Test Plan: Ran `differential.revision.search`, saw cost drop from ~195ms to ~170ms locally. Reviewers: yelirekim, chad Reviewed By: chad Maniphest Tasks: T11404 Differential Revision: https://secure.phabricator.com/D16355
This commit is contained in:
parent
64886b11d8
commit
1b192f746a
1 changed files with 11 additions and 11 deletions
|
@ -112,14 +112,13 @@ abstract class PhabricatorCustomField extends Phobject {
|
|||
$object,
|
||||
array $options = array()) {
|
||||
|
||||
$field_objects = id(new PhutilSymbolLoader())
|
||||
$field_objects = id(new PhutilClassMapQuery())
|
||||
->setAncestorClass($base_class)
|
||||
->loadObjects();
|
||||
->execute();
|
||||
|
||||
$fields = array();
|
||||
$from_map = array();
|
||||
foreach ($field_objects as $field_object) {
|
||||
$current_class = get_class($field_object);
|
||||
$field_object = clone $field_object;
|
||||
foreach ($field_object->createFields($object) as $field) {
|
||||
$key = $field->getFieldKey();
|
||||
if (isset($fields[$key])) {
|
||||
|
@ -127,11 +126,10 @@ abstract class PhabricatorCustomField extends Phobject {
|
|||
pht(
|
||||
"Both '%s' and '%s' define a custom field with ".
|
||||
"field key '%s'. Field keys must be unique.",
|
||||
$from_map[$key],
|
||||
$current_class,
|
||||
get_class($fields[$key]),
|
||||
get_class($field),
|
||||
$key));
|
||||
}
|
||||
$from_map[$key] = $current_class;
|
||||
$fields[$key] = $field;
|
||||
}
|
||||
}
|
||||
|
@ -146,11 +144,13 @@ abstract class PhabricatorCustomField extends Phobject {
|
|||
|
||||
if (empty($options['withDisabled'])) {
|
||||
foreach ($fields as $key => $field) {
|
||||
$config = idx($spec, $key, array()) + array(
|
||||
'disabled' => $field->shouldDisableByDefault(),
|
||||
);
|
||||
if (isset($spec[$key]['disabled'])) {
|
||||
$is_disabled = $spec[$key]['disabled'];
|
||||
} else {
|
||||
$is_disabled = $field->shouldDisableByDefault();
|
||||
}
|
||||
|
||||
if (!empty($config['disabled'])) {
|
||||
if ($is_disabled) {
|
||||
if ($field->canDisableField()) {
|
||||
unset($fields[$key]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue