mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 18:22:41 +01:00
Add database configuration source to the source stack
Summary: Read configuration from the new database source. This adds an extra MySQL connect + query to every page. They're very cheap so I think we can suffer them for now, but I'd like to put cache in front of this at some point. The difficulties are: - If we use APC, multi-frontend installs (Facebook) can't dirty it (major problem), and the CLI can't dirty it (fine for now, maybe a major problem later). - If we use Memcache, we need to add config stuff. - We could use APC in all non-Facebook installs if we can make it dirtyable from the CLI, but I don't see a reasonable way to do that. - We don't have any other caches which are faster than the database. So I'll probably implement Memcache support at some point, although this is a lame excuse for it. Test Plan: Added some config values via web UI, saw them active on the install. Reviewers: btrahan, codeblock, vrana Reviewed By: codeblock CC: aran Maniphest Tasks: T2221 Differential Revision: https://secure.phabricator.com/D4296
This commit is contained in:
parent
141d479104
commit
74cb7a8971
3 changed files with 31 additions and 2 deletions
|
@ -702,6 +702,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorConduitTokenController' => 'applications/conduit/controller/PhabricatorConduitTokenController.php',
|
||||
'PhabricatorConfigAllController' => 'applications/config/controller/PhabricatorConfigAllController.php',
|
||||
'PhabricatorConfigController' => 'applications/config/controller/PhabricatorConfigController.php',
|
||||
'PhabricatorConfigDatabaseSource' => 'infrastructure/env/PhabricatorConfigDatabaseSource.php',
|
||||
'PhabricatorConfigDefaultSource' => 'infrastructure/env/PhabricatorConfigDefaultSource.php',
|
||||
'PhabricatorConfigDictionarySource' => 'infrastructure/env/PhabricatorConfigDictionarySource.php',
|
||||
'PhabricatorConfigEditController' => 'applications/config/controller/PhabricatorConfigEditController.php',
|
||||
|
@ -2089,6 +2090,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorConduitTokenController' => 'PhabricatorConduitController',
|
||||
'PhabricatorConfigAllController' => 'PhabricatorConfigController',
|
||||
'PhabricatorConfigController' => 'PhabricatorController',
|
||||
'PhabricatorConfigDatabaseSource' => 'PhabricatorConfigProxySource',
|
||||
'PhabricatorConfigDefaultSource' => 'PhabricatorConfigProxySource',
|
||||
'PhabricatorConfigDictionarySource' => 'PhabricatorConfigSource',
|
||||
'PhabricatorConfigEditController' => 'PhabricatorConfigController',
|
||||
|
|
23
src/infrastructure/env/PhabricatorConfigDatabaseSource.php
vendored
Normal file
23
src/infrastructure/env/PhabricatorConfigDatabaseSource.php
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorConfigDatabaseSource
|
||||
extends PhabricatorConfigProxySource {
|
||||
|
||||
public function __construct($namespace) {
|
||||
$config = $this->loadConfig($namespace);
|
||||
$this->setSource(new PhabricatorConfigDictionarySource($config));
|
||||
}
|
||||
|
||||
public function isWritable() {
|
||||
// While this is writable, writes occur through the Config application.
|
||||
return false;
|
||||
}
|
||||
|
||||
private function loadConfig($namespace) {
|
||||
$objects = id(new PhabricatorConfigEntry())->loadAllWhere(
|
||||
'namespace = %s AND isDeleted = 0',
|
||||
$namespace);
|
||||
return mpull($objects, 'getValue', 'getConfigKey');
|
||||
}
|
||||
|
||||
}
|
8
src/infrastructure/env/PhabricatorEnv.php
vendored
8
src/infrastructure/env/PhabricatorEnv.php
vendored
|
@ -102,8 +102,6 @@ final class PhabricatorEnv {
|
|||
|
||||
|
||||
private static function initializeCommonEnvironment() {
|
||||
$env = self::getSelectedEnvironmentName();
|
||||
|
||||
self::buildConfigurationSourceStack();
|
||||
|
||||
PhutilErrorHandler::initialize();
|
||||
|
@ -149,6 +147,12 @@ final class PhabricatorEnv {
|
|||
$stack->pushSource(
|
||||
id(new PhabricatorConfigLocalSource())
|
||||
->setName(pht("Local Config")));
|
||||
|
||||
// NOTE: This must happen after the other sources are pushed, because it
|
||||
// will draw from lower-level config to bootstrap itself.
|
||||
$stack->pushSource(
|
||||
id(new PhabricatorConfigDatabaseSource('default'))
|
||||
->setName(pht("Database")));
|
||||
}
|
||||
|
||||
public static function getSelectedEnvironmentName() {
|
||||
|
|
Loading…
Reference in a new issue