modify
This commit is contained in:
@@ -41,7 +41,8 @@ class Connection extends Component
|
|||||||
|
|
||||||
public int $timeout = 1900;
|
public int $timeout = 1900;
|
||||||
|
|
||||||
public int $maxNumber = 200;
|
public int $maxNumber = 30;
|
||||||
|
public int $minNumber = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ class DatabasesProviders extends Providers
|
|||||||
return $application->get('databases.' . $name);
|
return $application->get('databases.' . $name);
|
||||||
}
|
}
|
||||||
$config = $this->getConfig($name);
|
$config = $this->getConfig($name);
|
||||||
|
|
||||||
|
$max = Config::get('databases.pool.max', 30);
|
||||||
return $application->set('databases.' . $name, [
|
return $application->set('databases.' . $name, [
|
||||||
'class' => Connection::class,
|
'class' => Connection::class,
|
||||||
'id' => $config['id'],
|
'id' => $config['id'],
|
||||||
@@ -58,7 +60,7 @@ class DatabasesProviders extends Providers
|
|||||||
'username' => $config['username'],
|
'username' => $config['username'],
|
||||||
'password' => $config['password'],
|
'password' => $config['password'],
|
||||||
'tablePrefix' => $config['tablePrefix'],
|
'tablePrefix' => $config['tablePrefix'],
|
||||||
'maxNumber' => $config['maxNumber'],
|
'maxNumber' => $max,
|
||||||
'database' => $config['database'],
|
'database' => $config['database'],
|
||||||
'charset' => $config['charset'] ?? 'utf8mb4',
|
'charset' => $config['charset'] ?? 'utf8mb4',
|
||||||
'slaveConfig' => $config['slaveConfig']
|
'slaveConfig' => $config['slaveConfig']
|
||||||
@@ -72,15 +74,15 @@ class DatabasesProviders extends Providers
|
|||||||
*/
|
*/
|
||||||
public function createPool()
|
public function createPool()
|
||||||
{
|
{
|
||||||
$databases = Config::get('databases', []);
|
$databases = Config::get('databases.connections', []);
|
||||||
if (empty($databases)) {
|
if (empty($databases)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$max = Config::get('databases.pool', ['max' => 10, 'min' => 10]);
|
||||||
|
|
||||||
$application = Snowflake::app();
|
$application = Snowflake::app();
|
||||||
foreach ($databases as $name => $database) {
|
foreach ($databases as $name => $database) {
|
||||||
|
|
||||||
var_dump($database);
|
|
||||||
|
|
||||||
/** @var Connection $connection */
|
/** @var Connection $connection */
|
||||||
$connection = $application->set('databases.' . $name, [
|
$connection = $application->set('databases.' . $name, [
|
||||||
'class' => Connection::class,
|
'class' => Connection::class,
|
||||||
@@ -90,7 +92,8 @@ class DatabasesProviders extends Providers
|
|||||||
'password' => $database['password'],
|
'password' => $database['password'],
|
||||||
'tablePrefix' => $database['tablePrefix'],
|
'tablePrefix' => $database['tablePrefix'],
|
||||||
'database' => $database['database'],
|
'database' => $database['database'],
|
||||||
'maxNumber' => $database['maxNumber'],
|
'maxNumber' => $max['max'],
|
||||||
|
'minNumber' => $max['min'],
|
||||||
'charset' => $database['charset'] ?? 'utf8mb4',
|
'charset' => $database['charset'] ?? 'utf8mb4',
|
||||||
'slaveConfig' => $database['slaveConfig']
|
'slaveConfig' => $database['slaveConfig']
|
||||||
]);
|
]);
|
||||||
@@ -106,7 +109,7 @@ class DatabasesProviders extends Providers
|
|||||||
*/
|
*/
|
||||||
public function getConfig($name): mixed
|
public function getConfig($name): mixed
|
||||||
{
|
{
|
||||||
return Config::get('databases.' . $name,null, true);
|
return Config::get('databases.' . $name, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,9 @@ class Connection extends Pool
|
|||||||
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
|
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
|
||||||
return $pdo;
|
return $pdo;
|
||||||
}
|
}
|
||||||
|
/** @var PDO $connections */
|
||||||
$connections = $this->getFromChannel($coroutineName, $config);
|
$connections = $this->getFromChannel($coroutineName, $config);
|
||||||
|
$connections->query('use `' . $config['database'].'`');
|
||||||
if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) {
|
if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) {
|
||||||
$number > 0 && $connections->beginTransaction();
|
$number > 0 && $connections->beginTransaction();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user