From d07c69dbdb88f3a9fc535875502503e8fc6b3a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sat, 5 Sep 2020 01:23:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Pool/Connection.php | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index 520c6818..ed1f09c6 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -152,11 +152,11 @@ class Connection extends Pool [$coroutineId, $coroutineName] = $this->getIndex($config['cds'], $isMaster); if (Context::hasContext($coroutineName)) { return Context::getContext($coroutineName); - } else if ($this->size($coroutineName) < 1) { - return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config)); - } else { - return $this->getByChannel($coroutineName, $config); } + if ($this->size($coroutineName) < 1) { + return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config)); + } + return $this->getByChannel($coroutineName, $config); } @@ -186,23 +186,14 @@ class Connection extends Pool */ public function getByChannel($coroutineName, $config) { - $this->info('client has :' . $this->size($coroutineName)); [$time, $client] = $this->get($coroutineName, -1); - $this->info('client has create :' . ($this->hasCreate[$coroutineName] ?? 0) . ':' . $this->max); if ($client instanceof PDO) { return $this->saveClient($coroutineName, $client); } - unset($client); - if (($this->hasCreate[$coroutineName] ?? 0) >= $this->max) { - [$time, $client] = $this->get($coroutineName, -1); - - return $client; - } - - if ($this->size($coroutineName) < 1) { - return $this->saveClient($coroutineName, $this->nowClient($coroutineName, $config)); + if ($this->hasCreate[$coroutineName] > $this->max) { + return $this->get($coroutineName)[1]; } return $this->getByChannel($coroutineName, $config); } @@ -227,11 +218,8 @@ class Connection extends Pool */ private function nowClient($coroutineName, $config) { - if ($this->size($coroutineName) > 0) { - return $this->getByChannel($coroutineName, $config); - } - $client = $this->createConnect($config['cds'], $config['username'], $config['password']); $this->success('create db client -> ' . $config['cds'] . ':' . $this->size($coroutineName)); + $client = $this->createConnect($config['cds'], $config['username'], $config['password']); if (isset(Context::getContext('begin_' . $coroutineName)[Coroutine::getCid()])) { $number = Context::getContext('begin_' . $coroutineName)[Coroutine::getCid()]; $number > 0 && $client->beginTransaction();