1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Provide a local cache for PhabricatorEnv

Summary: We hit some env config fairly often (~200 calls on the home page) and it's not especially cheap right now. This saves about 10ms on home, which is ~8% of the page weight on my machine.

Test Plan: Clicked around, everything seemed fine. Unit tests.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D5512
This commit is contained in:
epriestley 2013-04-01 12:05:49 -07:00
parent 80e9fb72bb
commit cd07182e9c
2 changed files with 60 additions and 40 deletions

View file

@ -794,7 +794,7 @@ celerity_register_resource_map(array(
), ),
'aphront-panel-view-css' => 'aphront-panel-view-css' =>
array( array(
'uri' => '/res/5600525c/rsrc/css/aphront/panel-view.css', 'uri' => '/res/3d1420b3/rsrc/css/aphront/panel-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
@ -2975,7 +2975,7 @@ celerity_register_resource_map(array(
), ),
'phabricator-jump-nav' => 'phabricator-jump-nav' =>
array( array(
'uri' => '/res/b33dd475/rsrc/css/application/directory/phabricator-jump-nav.css', 'uri' => '/res/2e0e2211/rsrc/css/application/directory/phabricator-jump-nav.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
@ -3805,7 +3805,7 @@ celerity_register_resource_map(array(
), array( ), array(
'packages' => 'packages' =>
array( array(
'1f04085c' => '4fc2a8f9' =>
array( array(
'name' => 'core.pkg.css', 'name' => 'core.pkg.css',
'symbols' => 'symbols' =>
@ -3847,7 +3847,7 @@ celerity_register_resource_map(array(
34 => 'phabricator-object-item-list-view-css', 34 => 'phabricator-object-item-list-view-css',
35 => 'global-drag-and-drop-css', 35 => 'global-drag-and-drop-css',
), ),
'uri' => '/res/pkg/1f04085c/core.pkg.css', 'uri' => '/res/pkg/4fc2a8f9/core.pkg.css',
'type' => 'css', 'type' => 'css',
), ),
'def4c982' => 'def4c982' =>
@ -4038,16 +4038,16 @@ celerity_register_resource_map(array(
'reverse' => 'reverse' =>
array( array(
'aphront-attached-file-view-css' => '6b1fccc6', 'aphront-attached-file-view-css' => '6b1fccc6',
'aphront-dialog-view-css' => '1f04085c', 'aphront-dialog-view-css' => '4fc2a8f9',
'aphront-error-view-css' => '1f04085c', 'aphront-error-view-css' => '4fc2a8f9',
'aphront-form-view-css' => '1f04085c', 'aphront-form-view-css' => '4fc2a8f9',
'aphront-list-filter-view-css' => '1f04085c', 'aphront-list-filter-view-css' => '4fc2a8f9',
'aphront-pager-view-css' => '1f04085c', 'aphront-pager-view-css' => '4fc2a8f9',
'aphront-panel-view-css' => '1f04085c', 'aphront-panel-view-css' => '4fc2a8f9',
'aphront-table-view-css' => '1f04085c', 'aphront-table-view-css' => '4fc2a8f9',
'aphront-tokenizer-control-css' => '1f04085c', 'aphront-tokenizer-control-css' => '4fc2a8f9',
'aphront-tooltip-css' => '1f04085c', 'aphront-tooltip-css' => '4fc2a8f9',
'aphront-typeahead-control-css' => '1f04085c', 'aphront-typeahead-control-css' => '4fc2a8f9',
'differential-changeset-view-css' => '8aaacd1b', 'differential-changeset-view-css' => '8aaacd1b',
'differential-core-view-css' => '8aaacd1b', 'differential-core-view-css' => '8aaacd1b',
'differential-inline-comment-editor' => '67ea27d0', 'differential-inline-comment-editor' => '67ea27d0',
@ -4061,7 +4061,7 @@ celerity_register_resource_map(array(
'differential-table-of-contents-css' => '8aaacd1b', 'differential-table-of-contents-css' => '8aaacd1b',
'diffusion-commit-view-css' => 'c8ce2d88', 'diffusion-commit-view-css' => 'c8ce2d88',
'diffusion-icons-css' => 'c8ce2d88', 'diffusion-icons-css' => 'c8ce2d88',
'global-drag-and-drop-css' => '1f04085c', 'global-drag-and-drop-css' => '4fc2a8f9',
'inline-comment-summary-css' => '8aaacd1b', 'inline-comment-summary-css' => '8aaacd1b',
'javelin-aphlict' => 'def4c982', 'javelin-aphlict' => 'def4c982',
'javelin-behavior' => 'fe22443b', 'javelin-behavior' => 'fe22443b',
@ -4133,48 +4133,48 @@ celerity_register_resource_map(array(
'javelin-util' => 'fe22443b', 'javelin-util' => 'fe22443b',
'javelin-vector' => 'fe22443b', 'javelin-vector' => 'fe22443b',
'javelin-workflow' => 'fe22443b', 'javelin-workflow' => 'fe22443b',
'lightbox-attachment-css' => '1f04085c', 'lightbox-attachment-css' => '4fc2a8f9',
'maniphest-task-summary-css' => '6b1fccc6', 'maniphest-task-summary-css' => '6b1fccc6',
'maniphest-transaction-detail-css' => '6b1fccc6', 'maniphest-transaction-detail-css' => '6b1fccc6',
'phabricator-busy' => 'def4c982', 'phabricator-busy' => 'def4c982',
'phabricator-content-source-view-css' => '8aaacd1b', 'phabricator-content-source-view-css' => '8aaacd1b',
'phabricator-core-buttons-css' => '1f04085c', 'phabricator-core-buttons-css' => '4fc2a8f9',
'phabricator-core-css' => '1f04085c', 'phabricator-core-css' => '4fc2a8f9',
'phabricator-crumbs-view-css' => '1f04085c', 'phabricator-crumbs-view-css' => '4fc2a8f9',
'phabricator-directory-css' => '1f04085c', 'phabricator-directory-css' => '4fc2a8f9',
'phabricator-drag-and-drop-file-upload' => '67ea27d0', 'phabricator-drag-and-drop-file-upload' => '67ea27d0',
'phabricator-dropdown-menu' => 'def4c982', 'phabricator-dropdown-menu' => 'def4c982',
'phabricator-file-upload' => 'def4c982', 'phabricator-file-upload' => 'def4c982',
'phabricator-filetree-view-css' => '1f04085c', 'phabricator-filetree-view-css' => '4fc2a8f9',
'phabricator-flag-css' => '1f04085c', 'phabricator-flag-css' => '4fc2a8f9',
'phabricator-form-view-css' => '1f04085c', 'phabricator-form-view-css' => '4fc2a8f9',
'phabricator-header-view-css' => '1f04085c', 'phabricator-header-view-css' => '4fc2a8f9',
'phabricator-jump-nav' => '1f04085c', 'phabricator-jump-nav' => '4fc2a8f9',
'phabricator-keyboard-shortcut' => 'def4c982', 'phabricator-keyboard-shortcut' => 'def4c982',
'phabricator-keyboard-shortcut-manager' => 'def4c982', 'phabricator-keyboard-shortcut-manager' => 'def4c982',
'phabricator-main-menu-view' => '1f04085c', 'phabricator-main-menu-view' => '4fc2a8f9',
'phabricator-menu-item' => 'def4c982', 'phabricator-menu-item' => 'def4c982',
'phabricator-nav-view-css' => '1f04085c', 'phabricator-nav-view-css' => '4fc2a8f9',
'phabricator-notification' => 'def4c982', 'phabricator-notification' => 'def4c982',
'phabricator-notification-css' => '1f04085c', 'phabricator-notification-css' => '4fc2a8f9',
'phabricator-notification-menu-css' => '1f04085c', 'phabricator-notification-menu-css' => '4fc2a8f9',
'phabricator-object-item-list-view-css' => '1f04085c', 'phabricator-object-item-list-view-css' => '4fc2a8f9',
'phabricator-object-selector-css' => '8aaacd1b', 'phabricator-object-selector-css' => '8aaacd1b',
'phabricator-paste-file-upload' => 'def4c982', 'phabricator-paste-file-upload' => 'def4c982',
'phabricator-prefab' => 'def4c982', 'phabricator-prefab' => 'def4c982',
'phabricator-project-tag-css' => '6b1fccc6', 'phabricator-project-tag-css' => '6b1fccc6',
'phabricator-remarkup-css' => '1f04085c', 'phabricator-remarkup-css' => '4fc2a8f9',
'phabricator-shaped-request' => '67ea27d0', 'phabricator-shaped-request' => '67ea27d0',
'phabricator-side-menu-view-css' => '1f04085c', 'phabricator-side-menu-view-css' => '4fc2a8f9',
'phabricator-standard-page-view' => '1f04085c', 'phabricator-standard-page-view' => '4fc2a8f9',
'phabricator-textareautils' => 'def4c982', 'phabricator-textareautils' => 'def4c982',
'phabricator-tooltip' => 'def4c982', 'phabricator-tooltip' => 'def4c982',
'phabricator-transaction-view-css' => '1f04085c', 'phabricator-transaction-view-css' => '4fc2a8f9',
'phabricator-zindex-css' => '1f04085c', 'phabricator-zindex-css' => '4fc2a8f9',
'sprite-apps-large-css' => '1f04085c', 'sprite-apps-large-css' => '4fc2a8f9',
'sprite-gradient-css' => '1f04085c', 'sprite-gradient-css' => '4fc2a8f9',
'sprite-icon-css' => '1f04085c', 'sprite-icon-css' => '4fc2a8f9',
'sprite-menu-css' => '1f04085c', 'sprite-menu-css' => '4fc2a8f9',
'syntax-highlighting-css' => '1f04085c', 'syntax-highlighting-css' => '4fc2a8f9',
), ),
)); ));

View file

@ -54,6 +54,7 @@ final class PhabricatorEnv {
private static $repairSource; private static $repairSource;
private static $overrideSource; private static $overrideSource;
private static $requestBaseURI; private static $requestBaseURI;
private static $cache;
/** /**
* @phutil-external-symbol class PhabricatorStartup * @phutil-external-symbol class PhabricatorStartup
@ -112,6 +113,8 @@ final class PhabricatorEnv {
} }
private static function buildConfigurationSourceStack() { private static function buildConfigurationSourceStack() {
self::dropConfigCache();
$stack = new PhabricatorConfigStackSource(); $stack = new PhabricatorConfigStackSource();
self::$sourceStack = $stack; self::$sourceStack = $stack;
@ -160,6 +163,7 @@ final class PhabricatorEnv {
self::$sourceStack->pushSource(self::$repairSource); self::$sourceStack->pushSource(self::$repairSource);
} }
self::$repairSource->setKeys(array($key => $value)); self::$repairSource->setKeys(array($key => $value));
self::dropConfigCache();
} }
public static function overrideConfig($key, $value) { public static function overrideConfig($key, $value) {
@ -169,6 +173,7 @@ final class PhabricatorEnv {
self::$sourceStack->pushSource(self::$overrideSource); self::$sourceStack->pushSource(self::$overrideSource);
} }
self::$overrideSource->setKeys(array($key => $value)); self::$overrideSource->setKeys(array($key => $value));
self::dropConfigCache();
} }
public static function getUnrepairedEnvConfig($key, $default = null) { public static function getUnrepairedEnvConfig($key, $default = null) {
@ -220,8 +225,17 @@ final class PhabricatorEnv {
* @task read * @task read
*/ */
public static function getEnvConfig($key) { public static function getEnvConfig($key) {
if (isset(self::$cache[$key])) {
return self::$cache[$key];
}
if (array_key_exists($key, self::$cache)) {
return self::$cache[$key];
}
$result = self::$sourceStack->getKeys(array($key)); $result = self::$sourceStack->getKeys(array($key));
if (array_key_exists($key, $result)) { if (array_key_exists($key, $result)) {
self::$cache[$key] = $result[$key];
return $result[$key]; return $result[$key];
} else { } else {
throw new Exception("No config value specified for key '{$key}'."); throw new Exception("No config value specified for key '{$key}'.");
@ -335,6 +349,7 @@ final class PhabricatorEnv {
* @task test * @task test
*/ */
private static function pushTestEnvironment() { private static function pushTestEnvironment() {
self::dropConfigCache();
$source = new PhabricatorConfigDictionarySource(array()); $source = new PhabricatorConfigDictionarySource(array());
self::$sourceStack->pushSource($source); self::$sourceStack->pushSource($source);
return spl_object_hash($source); return spl_object_hash($source);
@ -345,6 +360,7 @@ final class PhabricatorEnv {
* @task test * @task test
*/ */
public static function popTestEnvironment($key) { public static function popTestEnvironment($key) {
self::dropConfigCache();
$source = self::$sourceStack->popSource(); $source = self::$sourceStack->popSource();
$stack_key = spl_object_hash($source); $stack_key = spl_object_hash($source);
if ($stack_key !== $key) { if ($stack_key !== $key) {
@ -478,4 +494,8 @@ final class PhabricatorEnv {
} }
} }
private static function dropConfigCache() {
self::$cache = array();
}
} }