From c735776e5892416b7c9a61edb6da279fdd84d9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 14 Jan 2022 15:52:38 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=94=B9=E5=90=8D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fdf58326 --- Connection.php | 16 +++++++++++----- DatabasesProviders.php | 2 +- Mysql/PDO.php | 2 -- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Connection.php b/Connection.php index f84bde5..df11d04 100644 --- a/Connection.php +++ b/Connection.php @@ -17,15 +17,13 @@ use Database\Affair\Rollback; use Database\Mysql\PDO; use Database\Mysql\Schema; use Exception; +use Kiri; use Kiri\Abstracts\Component; use Kiri\Abstracts\Config; -use Kiri\Events\EventProvider; use Kiri\Exception\NotFindClassException; -use Kiri; -use Kiri\Annotation\Inject; -use ReflectionException; use Kiri\Server\Events\OnWorkerExit; use Kiri\Server\Events\OnWorkerStop; +use ReflectionException; /** * Class Connection @@ -99,7 +97,7 @@ class Connection extends Component /** * @throws Exception */ - public function fill() + public function fill($config) { $connections = $this->connections(); $pool = Config::get('databases.pool.max', 10); @@ -108,6 +106,14 @@ class Connection extends Component if (!empty($this->slaveConfig) && $this->cds != $this->slaveConfig['cds']) { $connections->initConnections('Mysql:' . $this->slaveConfig['cds'], false, $pool); } + $name = $connections->name('Mysql:' . $this->cds, true); + for ($i = 0; $i < $pool; $i++) { + $pool->push($name, $connections->create($name, $config)); + } + $name = $connections->name('Mysql:' . $this->cds, false); + for ($i = 0; $i < $pool; $i++) { + $pool->push($name, $connections->create($name, $config)); + } } diff --git a/DatabasesProviders.php b/DatabasesProviders.php index 3e94480..098d59c 100644 --- a/DatabasesProviders.php +++ b/DatabasesProviders.php @@ -57,7 +57,7 @@ class DatabasesProviders extends Providers $database = $this->_settings($database); $connection = Kiri::getDi()->create(Connection::class, [$database]); - $connection->fill(); + $connection->fill($database); $app->set($key, $connection); } diff --git a/Mysql/PDO.php b/Mysql/PDO.php index 7de65d1..bead5d0 100644 --- a/Mysql/PDO.php +++ b/Mysql/PDO.php @@ -114,8 +114,6 @@ class PDO implements StopHeartbeatCheck if (time() - $this->_last > (int)Config::get('databases.pool.tick', 60)) { $this->stopHeartbeatCheck(); - $this->eventProvider->off(OnWorkerExit::class, [$this, 'stopHeartbeatCheck']); - $this->pdo = null; } } catch (\Throwable $throwable) {