modify plugin name
This commit is contained in:
+2
-2
@@ -151,7 +151,7 @@ class Command extends Component
|
||||
} catch (\Throwable $exception) {
|
||||
$result = $this->logger->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql');
|
||||
} finally {
|
||||
$this->db->release();
|
||||
$this->db->release($pdo, true);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ class Command extends Component
|
||||
} catch (\Throwable $throwable) {
|
||||
$data = $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql');
|
||||
} finally {
|
||||
$this->db->release();
|
||||
$this->db->release($pdo, false);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-84
@@ -92,13 +92,13 @@ class Connection extends Component
|
||||
|
||||
|
||||
/**
|
||||
* @param null $sql
|
||||
* @param $isSearch
|
||||
* @return PDO
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getConnect($sql = NULL): PDO
|
||||
public function getConnect($isSearch): PDO
|
||||
{
|
||||
return $this->getPdo($sql);
|
||||
return !$isSearch ? $this->masterInstance() : $this->slaveInstance();
|
||||
}
|
||||
|
||||
|
||||
@@ -117,20 +117,6 @@ class Connection extends Component
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $sql
|
||||
* @return PDO
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getPdo($sql): PDO
|
||||
{
|
||||
if ($this->isWrite($sql)) {
|
||||
return $this->masterInstance();
|
||||
} else {
|
||||
return $this->slaveInstance();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
@@ -148,30 +134,6 @@ class Connection extends Component
|
||||
return $this->_schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sql
|
||||
* @return bool
|
||||
*/
|
||||
public function isWrite($sql): bool
|
||||
{
|
||||
if (empty($sql)) return false;
|
||||
if (str_starts_with(strtolower($sql), 'select')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getCacheDriver(): mixed
|
||||
{
|
||||
if (!$this->enableCache) {
|
||||
return null;
|
||||
}
|
||||
return Kiri::app()->get($this->cacheDriver);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PDO
|
||||
@@ -188,7 +150,7 @@ class Connection extends Component
|
||||
'read_timeout' => $this->read_timeout,
|
||||
'dbname' => $this->database,
|
||||
'pool' => $this->pool
|
||||
], true);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,20 +218,6 @@ class Connection extends Component
|
||||
$this->release();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sql
|
||||
* @return PDO
|
||||
* @throws Exception
|
||||
*/
|
||||
public function refresh($sql): PDO
|
||||
{
|
||||
if ($this->isWrite($sql)) {
|
||||
$instance = $this->masterInstance();
|
||||
} else {
|
||||
$instance = $this->slaveInstance();
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $sql
|
||||
@@ -289,39 +237,20 @@ class Connection extends Component
|
||||
* 回收链接
|
||||
* @throws
|
||||
*/
|
||||
public function release()
|
||||
{
|
||||
if (!Kiri::isWorker() && !Kiri::isProcess()) {
|
||||
$this->clear_connection();
|
||||
return;
|
||||
}
|
||||
$connections = $this->connections();
|
||||
$connections->release($this->cds);
|
||||
|
||||
if (empty($this->slaveConfig) || !isset($this->slaveConfig['cds'])) {
|
||||
$this->slaveConfig['cds'] = $this->cds;
|
||||
}
|
||||
|
||||
$connections->release($this->slaveConfig['cds']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function recovery()
|
||||
public function release($pdo, $isMaster)
|
||||
{
|
||||
$connections = $this->connections();
|
||||
|
||||
$connections->release($this->cds);
|
||||
|
||||
if (empty($this->slaveConfig) || !isset($this->slaveConfig['cds'])) {
|
||||
$this->slaveConfig['cds'] = $this->cds;
|
||||
if (!$isMaster) {
|
||||
if (empty($this->slaveConfig) || !isset($this->slaveConfig['cds'])) {
|
||||
$this->slaveConfig['cds'] = $this->cds;
|
||||
}
|
||||
$connections->addItem($this->slaveConfig['cds'], $pdo);
|
||||
} else {
|
||||
$connections->addItem($this->cds, $pdo);
|
||||
}
|
||||
|
||||
$connections->release($this->slaveConfig['cds']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 回收链接
|
||||
|
||||
Reference in New Issue
Block a user