改名
This commit is contained in:
+4
-32
@@ -11,13 +11,9 @@ namespace Database;
|
|||||||
|
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use JetBrains\PhpStorm\Pure;
|
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOStatement;
|
use PDOStatement;
|
||||||
use Snowflake\Abstracts\Component;
|
use Snowflake\Abstracts\Component;
|
||||||
use Snowflake\Core\Json;
|
|
||||||
use Snowflake\Error\LoggerProcess;
|
|
||||||
use Snowflake\Snowflake;
|
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,49 +120,25 @@ class Command extends Component
|
|||||||
*/
|
*/
|
||||||
private function execute($type, $isInsert = null, $hasAutoIncrement = null): int|bool|array|string|null
|
private function execute($type, $isInsert = null, $hasAutoIncrement = null): int|bool|array|string|null
|
||||||
{
|
{
|
||||||
$time = microtime(true);
|
|
||||||
try {
|
try {
|
||||||
|
$time = microtime(true);
|
||||||
if ($type === static::EXECUTE) {
|
if ($type === static::EXECUTE) {
|
||||||
$result = $this->insert_or_change($isInsert, $hasAutoIncrement);
|
$result = $this->insert_or_change($isInsert, $hasAutoIncrement);
|
||||||
} else {
|
} else {
|
||||||
$result = $this->search($type);
|
$result = $this->search($type);
|
||||||
}
|
}
|
||||||
if (microtime(true) - $time >= 0.03) {
|
if (microtime(true) - $time >= 0.02) {
|
||||||
$this->warning('execute sql Worker.' . env('worker') . '.' . Coroutine::getCid() . '`' . $this->sql . '` use time ' . (microtime(true) - $time));
|
$this->warning('execute sql Worker.' . env('worker') . '.' . Coroutine::getCid() . '`' . $this->sql . '` use time ' . (microtime(true) - $time));
|
||||||
}
|
}
|
||||||
|
return $result;
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$message = $this->sql . '. error: ' . $exception->getMessage();
|
$message = $this->sql . '. error: ' . $exception->getMessage();
|
||||||
|
|
||||||
$result = $this->addError($message, 'mysql');
|
return $this->addError($message, 'mysql');
|
||||||
} finally {
|
|
||||||
return $this->setExecuteLog($time, $result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $time
|
|
||||||
* @param $result
|
|
||||||
* @return mixed
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
#[Pure] private function setExecuteLog($time, $result): mixed
|
|
||||||
{
|
|
||||||
$export['sql'] = $this->sql;
|
|
||||||
$export['param'] = $this->params;
|
|
||||||
$export['startTime'] = $time;
|
|
||||||
$export['endTime'] = microtime(true);
|
|
||||||
$export['time'] = $export['endTime'] - $time;
|
|
||||||
|
|
||||||
|
|
||||||
/** @var LoggerProcess $logger */
|
|
||||||
$logger = Snowflake::getApp(LoggerProcess::class);
|
|
||||||
$logger->write(Json::encode([Json::encode($export), 'mysql']));
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $type
|
* @param $type
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|||||||
Reference in New Issue
Block a user