Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add styling for queries which are run inside a transaction #1032

Merged
merged 3 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Database/Log/DebugLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class DebugLog extends AbstractLogger
*/
protected bool $_includeSchema = false;

/**
* Whether a transaction is currently open or not.
*
* @var bool
*/
protected bool $inTransaction = false;

/**
* Constructor
*
Expand Down Expand Up @@ -162,11 +169,25 @@ public function log($level, string|Stringable $message, array $context = []): vo

$this->_totalTime += $data['took'];

$sql = (string)$query;
$isBegin = $sql === 'BEGIN';
$isCommitOrRollback = $sql === 'COMMIT' || $sql === 'ROLLBACK';

if ($isBegin) {
$this->inTransaction = true;
}

$this->_queries[] = [
'query' => (string)$query,
'query' => $sql,
'took' => $data['took'],
'rows' => $data['numRows'],
'inTransaction' => $this->inTransaction,
'isCommitOrRollback' => $isCommitOrRollback,
];

if ($isCommitOrRollback) {
$this->inTransaction = false;
}
}

/**
Expand Down
10 changes: 8 additions & 2 deletions templates/element/sql_log_panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</thead>
<tbody>
<?php foreach ($queries as $query) : ?>
<tr>
<tr<?= $query['inTransaction'] ? ' class="in-transaction"' : '' ?>>
<td>
<?=
(new SqlFormatter(
Expand All @@ -91,6 +91,12 @@
<td><?= h($query['rows']) ?></td>
<td><?= h($query['took']) ?></td>
</tr>
<?php if($query['isCommitOrRollback']): ?>
LordSimal marked this conversation as resolved.
Show resolved Hide resolved
<tr>
<td colspan="3" class="commit-or-rollback">
</td>
</tr>
<?php endif; ?>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to add space between the queries.

<?php endforeach; ?>
</tbody>
</table>
Expand All @@ -99,6 +105,6 @@
<?php endif; ?>

<?php if ($noOutput) : ?>
<div class="c-flash c-flash--warning">No active database connections</div>
<div class="c-flash c-flash--warning">No active database connections</div>
<?php endif ?>
</div>
6 changes: 6 additions & 0 deletions webroot/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
--packages-warning: #ffcc00;
--packages-link: #000;

--sql-log-transaction: #d8d8d8;
LordSimal marked this conversation as resolved.
Show resolved Hide resolved

--routes-btn-active-bg: #fff;
--routes-btn-active-text: #555;
--routes-btn-active-border: #6f6f6f;
Expand Down Expand Up @@ -605,6 +607,10 @@ strong {
box-shadow: 0 2px 0 var(--routes-btn-active-border);
}

.c-sql-log-panel__entry .in-transaction {
background: var(--sql-log-transaction);
LordSimal marked this conversation as resolved.
Show resolved Hide resolved
}

.c-toolbar {
display: flex;
background: var(--toolbar-bg);
Expand Down