mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52: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 {
|
try {
|
||||||
queryfx(
|
queryfx(
|
||||||
$api->getConn('meta_data', $select_database = false),
|
$api->getConn(null),
|
||||||
'SELECT 1');
|
'SELECT 1');
|
||||||
} catch (AphrontQueryException $ex) {
|
} catch (AphrontQueryException $ex) {
|
||||||
echo phutil_console_format(
|
echo phutil_console_format(
|
||||||
|
|
|
@ -6,6 +6,7 @@ final class PhabricatorStorageManagementAPI {
|
||||||
private $user;
|
private $user;
|
||||||
private $password;
|
private $password;
|
||||||
private $namespace;
|
private $namespace;
|
||||||
|
private $conns = array();
|
||||||
|
|
||||||
public function setNamespace($namespace) {
|
public function setNamespace($namespace) {
|
||||||
$this->namespace = $namespace;
|
$this->namespace = $namespace;
|
||||||
|
@ -62,20 +63,25 @@ final class PhabricatorStorageManagementAPI {
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConn($fragment, $select_database = true) {
|
public function getConn($fragment) {
|
||||||
return PhabricatorEnv::newObjectFromConfig(
|
$database = $this->getDatabaseName($fragment);
|
||||||
|
$return = &$this->conns[$this->host][$this->user][$database];
|
||||||
|
if (!$return) {
|
||||||
|
$return = PhabricatorEnv::newObjectFromConfig(
|
||||||
'mysql.implementation',
|
'mysql.implementation',
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'user' => $this->user,
|
'user' => $this->user,
|
||||||
'pass' => $this->password,
|
'pass' => $this->password,
|
||||||
'host' => $this->host,
|
'host' => $this->host,
|
||||||
'database' => $select_database
|
'database' => $fragment
|
||||||
? $this->getDatabaseName($fragment)
|
? $database
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
public function getAppliedPatches() {
|
public function getAppliedPatches() {
|
||||||
try {
|
try {
|
||||||
|
@ -90,7 +96,7 @@ final class PhabricatorStorageManagementAPI {
|
||||||
|
|
||||||
public function createDatabase($fragment) {
|
public function createDatabase($fragment) {
|
||||||
queryfx(
|
queryfx(
|
||||||
$this->getConn($fragment, $select_database = false),
|
$this->getConn(null),
|
||||||
'CREATE DATABASE IF NOT EXISTS %T COLLATE utf8_general_ci',
|
'CREATE DATABASE IF NOT EXISTS %T COLLATE utf8_general_ci',
|
||||||
$this->getDatabaseName($fragment));
|
$this->getDatabaseName($fragment));
|
||||||
}
|
}
|
||||||
|
@ -160,7 +166,7 @@ final class PhabricatorStorageManagementAPI {
|
||||||
$queries = preg_split('/;\s+/', $sql);
|
$queries = preg_split('/;\s+/', $sql);
|
||||||
$queries = array_filter($queries);
|
$queries = array_filter($queries);
|
||||||
|
|
||||||
$conn = $this->getConn('meta_data', $select_database = false);
|
$conn = $this->getConn(null);
|
||||||
|
|
||||||
foreach ($queries as $query) {
|
foreach ($queries as $query) {
|
||||||
$query = str_replace('{$NAMESPACE}', $this->namespace, $query);
|
$query = str_replace('{$NAMESPACE}', $this->namespace, $query);
|
||||||
|
@ -172,7 +178,7 @@ final class PhabricatorStorageManagementAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyPatchPHP($script) {
|
public function applyPatchPHP($script) {
|
||||||
$schema_conn = $this->getConn('meta_data', $select_database = false);
|
$schema_conn = $this->getConn(null);
|
||||||
require_once $script;
|
require_once $script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ final class PhabricatorStorageManagementDestroyWorkflow
|
||||||
$patches = $this->getPatches();
|
$patches = $this->getPatches();
|
||||||
|
|
||||||
if ($args->getArg('unittest-fixtures')) {
|
if ($args->getArg('unittest-fixtures')) {
|
||||||
$conn = $api->getConn(null, false);
|
$conn = $api->getConn(null);
|
||||||
$databases = queryfx_all(
|
$databases = queryfx_all(
|
||||||
$conn,
|
$conn,
|
||||||
'SELECT DISTINCT(TABLE_SCHEMA) AS db '.
|
'SELECT DISTINCT(TABLE_SCHEMA) AS db '.
|
||||||
|
@ -64,7 +64,7 @@ final class PhabricatorStorageManagementDestroyWorkflow
|
||||||
} else {
|
} else {
|
||||||
echo "Dropping database '{$database}'...\n";
|
echo "Dropping database '{$database}'...\n";
|
||||||
queryfx(
|
queryfx(
|
||||||
$api->getConn('meta_data', $select_database = false),
|
$api->getConn(null),
|
||||||
'DROP DATABASE IF EXISTS %T',
|
'DROP DATABASE IF EXISTS %T',
|
||||||
$database);
|
$database);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue