Update query log on requests

This commit is contained in:
Sky Johnson 2024-12-18 11:09:00 -06:00
parent 8084a84576
commit 58012f5808
3 changed files with 14 additions and 21 deletions

View File

@ -53,6 +53,8 @@ $content = $l['handler'](...$l['params'] ?? []);
if (is_htmx()) {
$content .= '<title>'.page_title().'</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();
}

View File

@ -43,3 +43,14 @@ function babblebox(): string
{
return render('babblebox', ['messages' => babblebox_messages()]);
}
function debug_query_log(): string
{
$html = '<pre id="debug-query-log" hx-swap-oob="true">';
foreach (db()->log as $record) {
$query_string = str_replace(["\r\n", "\n", "\r"], ' ', $record[0]);
$error_string = !empty($record[2]) ? '// '.$record[2] : '';
$html .= '<div>['.round($record[1], 2)."s] {$query_string}{$error_string}</div>";
}
return $html . '</pre>';
}

View File

@ -40,27 +40,7 @@
<div>Version <?= VERSION ?> <?= BUILD ?></div>
</footer>
<?php
if (env('debug', false)) {
echo '<pre>';
foreach (db()->log as $record) {
$query_string = str_replace(["\r\n", "\n", "\r"], ' ', $record[0]);
$error_string = !empty($record[2]) ? '// '.$record[2] : '';
echo '<div>['.round($record[1], 2)."s] {$query_string}{$error_string}</div>";
}
echo '</pre>';
}
?>
<?php if (env('debug', false)) echo Render\debug_query_log(); ?>
</div>
<script>
document.addEventListener("updateTitle", (event) => {
const title = event.detail?.title
if (title) {
console.log('New title:', title);
document.title = title;
}
})
</script>
</body>
</html>