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