Commit 60343693 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix DebugBar production crash and guard Database instrumentation

DebugBar used self:: in heredoc causing undefined variable fatal error.
Database query instrumentation now wrapped in try/catch so logging/debug
can never crash actual queries.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 520392ae
......@@ -41,6 +41,7 @@ class Database
$stmt->execute($params);
$elapsed = microtime(true) - $start;
try {
DebugBar::recordQuery($elapsed);
if ($elapsed > 0.1) {
......@@ -54,6 +55,8 @@ class Database
Logger::warning("N+1 detected: table '{$table}' queried 11+ times in single request");
}
}
} catch (\Throwable $e) {
}
return $stmt;
}
......
......@@ -5,7 +5,7 @@ namespace App\Core;
final class DebugBar
{
private static float $startTime;
private static float $startTime = 0;
private static int $queryCount = 0;
private static float $queryTime = 0.0;
......@@ -22,13 +22,12 @@ final class DebugBar
public static function render(): string
{
$totalTime = round((microtime(true) - self::$startTime) * 1000);
$totalTime = self::$startTime > 0 ? round((microtime(true) - self::$startTime) * 1000) : 0;
$memory = round(memory_get_peak_usage(true) / 1024 / 1024, 1);
$queryCount = self::$queryCount;
$queryTime = round(self::$queryTime * 1000);
$app = App::getInstance();
$route = '-';
$permission = '-';
$employee = '-';
try {
......@@ -43,7 +42,7 @@ final class DebugBar
<div id="debug-bar" style="position:fixed;bottom:0;left:0;right:0;background:#1a1a2e;color:#e0e0e0;font-family:monospace;font-size:11px;padding:6px 15px;z-index:99999;direction:ltr;text-align:left;display:flex;gap:20px;align-items:center;border-top:2px solid #0D7377;">
<span style="color:#4ecdc4;font-weight:bold;">DEBUG</span>
<span>Time: <b>{$totalTime}ms</b></span>
<span>Queries: <b>{self::$queryCount}</b> ({$queryTime}ms)</span>
<span>Queries: <b>{$queryCount}</b> ({$queryTime}ms)</span>
<span>Memory: <b>{$memory}MB</b></span>
<span>Employee: <b>{$employee}</b></span>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment