Skip to content

Commit 87ffde8

Browse files
authored
Merge pull request #5196 from sfadschm/timeline-query-strings
[Debug] Add formatted query string to timeline.
2 parents 101db15 + 8d2678f commit 87ffde8

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

system/Debug/Toolbar.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,18 @@ protected function renderTimelineRecursive(array $rows, float $startTime, int $s
185185

186186
foreach ($rows as $row) {
187187
$hasChildren = isset($row['children']) && ! empty($row['children']);
188+
$isQuery = isset($row['query']) && ! empty($row['query']);
188189

190+
// Open controller timeline by default
189191
$open = $row['name'] === 'Controller';
190192

191-
if ($hasChildren) {
193+
if ($hasChildren || $isQuery) {
192194
$output .= '<tr class="timeline-parent' . ($open ? ' timeline-parent-open' : '') . '" id="timeline-' . $styleCount . '_parent" onclick="ciDebugBar.toggleChildRows(\'timeline-' . $styleCount . '\');">';
193195
} else {
194196
$output .= '<tr>';
195197
}
196198

197-
$output .= '<td class="' . ($isChild ? 'debug-bar-width30' : '') . '" style="--level: ' . $level . ';">' . ($hasChildren ? '<nav></nav>' : '') . $row['name'] . '</td>';
199+
$output .= '<td class="' . ($isChild ? 'debug-bar-width30' : '') . '" style="--level: ' . $level . ';">' . ($hasChildren || $isQuery ? '<nav></nav>' : '') . $row['name'] . '</td>';
198200
$output .= '<td class="' . ($isChild ? 'debug-bar-width10' : '') . '">' . $row['component'] . '</td>';
199201
$output .= '<td class="' . ($isChild ? 'debug-bar-width10 ' : '') . 'debug-bar-alignRight">' . number_format($row['duration'] * 1000, 2) . ' ms</td>';
200202
$output .= "<td class='debug-bar-noverflow' colspan='{$segmentCount}'>";
@@ -211,12 +213,22 @@ protected function renderTimelineRecursive(array $rows, float $startTime, int $s
211213
$styleCount++;
212214

213215
// Add children if any
214-
if ($hasChildren) {
216+
if ($hasChildren || $isQuery) {
215217
$output .= '<tr class="child-row" id="timeline-' . ($styleCount - 1) . '_children" style="' . ($open ? '' : 'display: none;') . '">';
216218
$output .= '<td colspan="' . ($segmentCount + 3) . '" class="child-container">';
217219
$output .= '<table class="timeline">';
218220
$output .= '<tbody>';
219-
$output .= $this->renderTimelineRecursive($row['children'], $startTime, $segmentCount, $segmentDuration, $styles, $styleCount, $level + 1, true);
221+
222+
if ($isQuery) {
223+
// Output query string if query
224+
$output .= '<tr>';
225+
$output .= '<td class="query-container" style="--level: ' . ($level + 1) . ';">' . $row['query'] . '</td>';
226+
$output .= '</tr>';
227+
} else {
228+
// Recursively render children
229+
$output .= $this->renderTimelineRecursive($row['children'], $startTime, $segmentCount, $segmentDuration, $styles, $styleCount, $level + 1, true);
230+
}
231+
220232
$output .= '</tbody>';
221233
$output .= '</table>';
222234
$output .= '</td>';

system/Debug/Toolbar/Collectors/Database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ protected function formatTimelineData(): array
118118
'component' => 'Database',
119119
'start' => $query['query']->getStartTime(true),
120120
'duration' => $query['query']->getDuration(),
121+
'query' => $query['query']->debugToolbarDisplay(),
121122
];
122123
}
123124

0 commit comments

Comments
 (0)