Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-14 15:52:38 +08:00
parent c5b4f4795b
commit c735776e58
3 changed files with 12 additions and 8 deletions
+11 -5
View File
@@ -17,15 +17,13 @@ use Database\Affair\Rollback;
use Database\Mysql\PDO; use Database\Mysql\PDO;
use Database\Mysql\Schema; use Database\Mysql\Schema;
use Exception; use Exception;
use Kiri;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Events\EventProvider;
use Kiri\Exception\NotFindClassException; use Kiri\Exception\NotFindClassException;
use Kiri;
use Kiri\Annotation\Inject;
use ReflectionException;
use Kiri\Server\Events\OnWorkerExit; use Kiri\Server\Events\OnWorkerExit;
use Kiri\Server\Events\OnWorkerStop; use Kiri\Server\Events\OnWorkerStop;
use ReflectionException;
/** /**
* Class Connection * Class Connection
@@ -99,7 +97,7 @@ class Connection extends Component
/** /**
* @throws Exception * @throws Exception
*/ */
public function fill() public function fill($config)
{ {
$connections = $this->connections(); $connections = $this->connections();
$pool = Config::get('databases.pool.max', 10); $pool = Config::get('databases.pool.max', 10);
@@ -108,6 +106,14 @@ class Connection extends Component
if (!empty($this->slaveConfig) && $this->cds != $this->slaveConfig['cds']) { if (!empty($this->slaveConfig) && $this->cds != $this->slaveConfig['cds']) {
$connections->initConnections('Mysql:' . $this->slaveConfig['cds'], false, $pool); $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));
}
} }
+1 -1
View File
@@ -57,7 +57,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(); $connection->fill($database);
$app->set($key, $connection); $app->set($key, $connection);
} }
-2
View File
@@ -114,8 +114,6 @@ class PDO implements StopHeartbeatCheck
if (time() - $this->_last > (int)Config::get('databases.pool.tick', 60)) { if (time() - $this->_last > (int)Config::get('databases.pool.tick', 60)) {
$this->stopHeartbeatCheck(); $this->stopHeartbeatCheck();
$this->eventProvider->off(OnWorkerExit::class, [$this, 'stopHeartbeatCheck']);
$this->pdo = null; $this->pdo = null;
} }
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {