mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-21 22:32:41 +01:00
Cache connection in bin/storage
Summary: Connection takes .3s from dev server to master. Test Plan: $ bin/storage --trace upgrade --namespace x $ bin/storage --trace destroy --namespace x Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4480
This commit is contained in:
parent
c7c25e141a
commit
aa3e95cbeb
3 changed files with 16 additions and 10 deletions
|
@ -85,7 +85,7 @@ $api->setNamespace($args->getArg('namespace'));
|
|||
|
||||
try {
|
||||
queryfx(
|
||||
$api->getConn('meta_data', $select_database = false),
|
||||
$api->getConn(null),
|
||||
'SELECT 1');
|
||||
} catch (AphrontQueryException $ex) {
|
||||
echo phutil_console_format(
|
||||
|
|
|
@ -6,6 +6,7 @@ final class PhabricatorStorageManagementAPI {
|
|||
private $user;
|
||||
private $password;
|
||||
private $namespace;
|
||||
private $conns = array();
|
||||
|
||||
public function setNamespace($namespace) {
|
||||
$this->namespace = $namespace;
|
||||
|
@ -62,19 +63,24 @@ final class PhabricatorStorageManagementAPI {
|
|||
return $list;
|
||||
}
|
||||
|
||||
public function getConn($fragment, $select_database = true) {
|
||||
return PhabricatorEnv::newObjectFromConfig(
|
||||
public function getConn($fragment) {
|
||||
$database = $this->getDatabaseName($fragment);
|
||||
$return = &$this->conns[$this->host][$this->user][$database];
|
||||
if (!$return) {
|
||||
$return = PhabricatorEnv::newObjectFromConfig(
|
||||
'mysql.implementation',
|
||||
array(
|
||||
array(
|
||||
'user' => $this->user,
|
||||
'pass' => $this->password,
|
||||
'host' => $this->host,
|
||||
'database' => $select_database
|
||||
? $this->getDatabaseName($fragment)
|
||||
'database' => $fragment
|
||||
? $database
|
||||
: null,
|
||||
),
|
||||
));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function getAppliedPatches() {
|
||||
|
@ -90,7 +96,7 @@ final class PhabricatorStorageManagementAPI {
|
|||
|
||||
public function createDatabase($fragment) {
|
||||
queryfx(
|
||||
$this->getConn($fragment, $select_database = false),
|
||||
$this->getConn(null),
|
||||
'CREATE DATABASE IF NOT EXISTS %T COLLATE utf8_general_ci',
|
||||
$this->getDatabaseName($fragment));
|
||||
}
|
||||
|
@ -160,7 +166,7 @@ final class PhabricatorStorageManagementAPI {
|
|||
$queries = preg_split('/;\s+/', $sql);
|
||||
$queries = array_filter($queries);
|
||||
|
||||
$conn = $this->getConn('meta_data', $select_database = false);
|
||||
$conn = $this->getConn(null);
|
||||
|
||||
foreach ($queries as $query) {
|
||||
$query = str_replace('{$NAMESPACE}', $this->namespace, $query);
|
||||
|
@ -172,7 +178,7 @@ final class PhabricatorStorageManagementAPI {
|
|||
}
|
||||
|
||||
public function applyPatchPHP($script) {
|
||||
$schema_conn = $this->getConn('meta_data', $select_database = false);
|
||||
$schema_conn = $this->getConn(null);
|
||||
require_once $script;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ final class PhabricatorStorageManagementDestroyWorkflow
|
|||
$patches = $this->getPatches();
|
||||
|
||||
if ($args->getArg('unittest-fixtures')) {
|
||||
$conn = $api->getConn(null, false);
|
||||
$conn = $api->getConn(null);
|
||||
$databases = queryfx_all(
|
||||
$conn,
|
||||
'SELECT DISTINCT(TABLE_SCHEMA) AS db '.
|
||||
|
@ -64,7 +64,7 @@ final class PhabricatorStorageManagementDestroyWorkflow
|
|||
} else {
|
||||
echo "Dropping database '{$database}'...\n";
|
||||
queryfx(
|
||||
$api->getConn('meta_data', $select_database = false),
|
||||
$api->getConn(null),
|
||||
'DROP DATABASE IF EXISTS %T',
|
||||
$database);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue