From 58012f5808aef879cc9cb78e59b415e0d886e713 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Wed, 18 Dec 2024 11:09:00 -0600 Subject: [PATCH] Update query log on requests --- public/index.php | 2 ++ src/render.php | 11 +++++++++++ templates/layouts/primary.php | 22 +--------------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/public/index.php b/public/index.php index 03fae53..8ac8a0c 100644 --- a/public/index.php +++ b/public/index.php @@ -53,6 +53,8 @@ $content = $l['handler'](...$l['params'] ?? []); if (is_htmx()) { $content .= ''.page_title().''; $content .= Render\debug_db_info(); + if (env('debug', false)) $content .= Render\debug_query_log(); + if ($GLOBALS['state']['user-state-changed'] ?? false) { $content .= Render\right_nav(); } diff --git a/src/render.php b/src/render.php index 09a675d..a4aff8f 100644 --- a/src/render.php +++ b/src/render.php @@ -43,3 +43,14 @@ function babblebox(): string { return render('babblebox', ['messages' => babblebox_messages()]); } + +function debug_query_log(): string +{ + $html = '
';
+	foreach (db()->log as $record) {
+		$query_string = str_replace(["\r\n", "\n", "\r"], ' ', $record[0]);
+		$error_string = !empty($record[2]) ? '// '.$record[2] : '';
+		$html .= '
['.round($record[1], 2)."s] {$query_string}{$error_string}
"; + } + return $html . '
'; +} diff --git a/templates/layouts/primary.php b/templates/layouts/primary.php index 9778832..cfe7be5 100644 --- a/templates/layouts/primary.php +++ b/templates/layouts/primary.php @@ -40,27 +40,7 @@
Version
- '; - foreach (db()->log as $record) { - $query_string = str_replace(["\r\n", "\n", "\r"], ' ', $record[0]); - $error_string = !empty($record[2]) ? '// '.$record[2] : ''; - echo '
['.round($record[1], 2)."s] {$query_string}{$error_string}
"; - } - echo ''; - } - ?> + - -