mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-29 07:12:15 +09:00
Completely disable Debug logging if it is not enabled for the current user
관리자 또는 특정 IP에서만 디버그 기능을 사용하도록 설정된 경우, 그 밖의 요청에서는 어떤 에러메시지, 쿼리, 트리거 소요시간 등의 기록도 디버그 클래스에 저장하지 않도록 변경합니다. 워닝이 많이 발생하는 PHP 8.0에서는 20~30%의 성능 개선 효과가 있습니다.
This commit is contained in:
parent
02122cb383
commit
1a204d8c52
11 changed files with 108 additions and 74 deletions
|
|
@ -530,7 +530,11 @@ class DB
|
|||
{
|
||||
$this->setError(-1, $e->getMessage());
|
||||
}
|
||||
Debug::addQuery($this->getQueryLog('START TRANSACTION', 0));
|
||||
|
||||
if (Debug::isEnabledForCurrentUser())
|
||||
{
|
||||
Debug::addQuery($this->getQueryLog('START TRANSACTION', 0));
|
||||
}
|
||||
}
|
||||
$this->_transaction_level++;
|
||||
return $this->_transaction_level;
|
||||
|
|
@ -554,7 +558,11 @@ class DB
|
|||
{
|
||||
$this->setError(-1, $e->getMessage());
|
||||
}
|
||||
Debug::addQuery($this->getQueryLog('ROLLBACK', 0));
|
||||
|
||||
if (Debug::isEnabledForCurrentUser())
|
||||
{
|
||||
Debug::addQuery($this->getQueryLog('ROLLBACK', 0));
|
||||
}
|
||||
}
|
||||
$this->_transaction_level--;
|
||||
return $this->_transaction_level;
|
||||
|
|
@ -578,7 +586,11 @@ class DB
|
|||
{
|
||||
$this->setError(-1, $e->getMessage());
|
||||
}
|
||||
Debug::addQuery($this->getQueryLog('COMMIT', 0));
|
||||
|
||||
if (Debug::isEnabledForCurrentUser())
|
||||
{
|
||||
Debug::addQuery($this->getQueryLog('COMMIT', 0));
|
||||
}
|
||||
}
|
||||
$this->_transaction_level--;
|
||||
return $this->_transaction_level;
|
||||
|
|
@ -1060,12 +1072,7 @@ class DB
|
|||
public function getQueryLog(string $query, float $elapsed_time): array
|
||||
{
|
||||
// Cache the debug status to improve performance.
|
||||
static $debug_enabled = null;
|
||||
static $debug_queries = null;
|
||||
if ($debug_enabled === null)
|
||||
{
|
||||
$debug_enabled = Config::get('debug.enabled');
|
||||
}
|
||||
if ($debug_queries === null)
|
||||
{
|
||||
$debug_queries = in_array('queries', Config::get('debug.display_content') ?: []);
|
||||
|
|
@ -1087,7 +1094,7 @@ class DB
|
|||
);
|
||||
|
||||
// Add debug information if enabled.
|
||||
if ($debug_enabled && ($this->_errno || $debug_queries))
|
||||
if ($this->_errno || $debug_queries)
|
||||
{
|
||||
$backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
foreach ($backtrace as $no => $call)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue