Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-14 16:23:15 +08:00
parent c1e480cd43
commit ac0c08f909
2 changed files with 34 additions and 23 deletions
+28 -17
View File
@@ -97,7 +97,7 @@ class Connection extends Component
/** /**
* @throws Exception * @throws Exception
*/ */
public function fill($config) public function fill()
{ {
$connections = $this->connections(); $connections = $this->connections();
$pool = Config::get('databases.pool.max', 10); $pool = Config::get('databases.pool.max', 10);
@@ -107,8 +107,33 @@ class Connection extends Component
$connections->initConnections('Mysql:' . $this->slaveConfig['cds'], false, $pool); $connections->initConnections('Mysql:' . $this->slaveConfig['cds'], false, $pool);
} }
$name = $connections->name('Mysql:' . $this->cds, true); $name = $connections->name('Mysql:' . $this->cds, true);
$config = $this->_config();
for ($i = 0; $i < $pool; $i++) { for ($i = 0; $i < $pool; $i++) {
$connections->addItem($name, $connections->create($name, [ $connections->addItem($name, $connections->create($name, $config)());
}
if (empty($this->slaveConfig)) {
return;
}
$config['cds'] = $this->slaveConfig['cds'];
$config['username'] = $this->slaveConfig['username'];
$config['password'] = $this->slaveConfig['password'];
$name = $connections->name('Mysql:' . $config['cds'], false);
for ($i = 0; $i < $pool; $i++) {
$connections->addItem($name, $connections->create($name, $config)());
}
}
/**
* @return array
*/
private function _config(): array
{
return [
'cds' => $this->cds, 'cds' => $this->cds,
'username' => $this->username, 'username' => $this->username,
'password' => $this->password, 'password' => $this->password,
@@ -117,21 +142,7 @@ class Connection extends Component
'read_timeout' => $this->read_timeout, 'read_timeout' => $this->read_timeout,
'dbname' => $this->database, 'dbname' => $this->database,
'pool' => $this->pool 'pool' => $this->pool
])()); ];
}
$name = $connections->name('Mysql:' . $this->cds, false);
for ($i = 0; $i < $pool; $i++) {
$connections->addItem($name, $connections->create($name, [
'cds' => $this->cds,
'username' => $this->username,
'password' => $this->password,
'attributes' => $this->attributes,
'connect_timeout' => $this->connect_timeout,
'read_timeout' => $this->read_timeout,
'dbname' => $this->database,
'pool' => $this->pool
])());
}
} }
+1 -1
View File
@@ -61,7 +61,7 @@ class DatabasesProviders extends Providers
$database = $this->_settings($database); $database = $this->_settings($database);
$connection = Kiri::getDi()->create(Connection::class, [$database]); $connection = Kiri::getDi()->create(Connection::class, [$database]);
$connection->fill($database); $connection->fill();
$app->set($key, $connection); $app->set($key, $connection);
} }