modify plugin name

This commit is contained in:
2022-06-08 14:08:31 +08:00
parent 56a20d0f90
commit c829192e9c
2 changed files with 13 additions and 11 deletions
+10 -6
View File
@@ -140,18 +140,20 @@ class Command extends Component
/** /**
* @param PDO $pdo
* @return bool|int * @return bool|int
* @throws Exception * @throws Exception
*/ */
private function _execute(PDO $pdo): bool|int private function _execute(): bool|int
{ {
try { try {
$pdo = $this->db->masterInstance();
$result = $pdo->execute($this->sql, $this->params); $result = $pdo->execute($this->sql, $this->params);
$this->db->release($pdo, true);
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$result = $this->logger->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql'); $result = $this->logger->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql');
} finally { } finally {
$this->db->release($pdo, true);
return $result; return $result;
} }
} }
@@ -159,18 +161,20 @@ class Command extends Component
/** /**
* @param string $type * @param string $type
* @param PDO $pdo
* @return array|int|bool|null * @return array|int|bool|null
* @throws Exception * @throws Exception
*/ */
private function search(string $type, PDO $pdo): array|int|bool|null private function search(string $type): array|int|bool|null
{ {
try { try {
$pdo = $this->db->slaveInstance();
$data = $pdo->{$type}($this->sql, $this->params); $data = $pdo->{$type}($this->sql, $this->params);
$this->db->release($pdo, false);
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
$data = $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql'); $data = $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql');
} finally { } finally {
$this->db->release($pdo, false);
return $data; return $data;
} }
} }
+3 -5
View File
@@ -94,7 +94,7 @@ class PDO implements StopHeartbeatCheck
public function heartbeat_check(): void public function heartbeat_check(): void
{ {
if ($this->_timer === -1) { if ($this->_timer === -1) {
$this->_timer = Timer::tick(1000, fn() => $this->waite()); $this->_timer = Timer::tick(1000, [$this, 'waite']);
} }
} }
@@ -105,10 +105,8 @@ class PDO implements StopHeartbeatCheck
private function waite(): void private function waite(): void
{ {
try { try {
if ($this->_timer == -1) { $tick = (int)Config::get('databases.pool.tick', 60);
$this->stopHeartbeatCheck(); if ($this->_timer == -1 || time() - $this->_last > $tick) {
}
if (time() - $this->_last > (int)Config::get('databases.pool.tick', 60)) {
$this->stopHeartbeatCheck(); $this->stopHeartbeatCheck();
$this->pdo = null; $this->pdo = null;