diff --git a/system/Debug/Toolbar/Collectors/Database.php b/system/Debug/Toolbar/Collectors/Database.php index d7e14d291b68..a589c8fdabb9 100644 --- a/system/Debug/Toolbar/Collectors/Database.php +++ b/system/Debug/Toolbar/Collectors/Database.php @@ -134,6 +134,8 @@ public function display(): array $data['queries'] = array_map(static function (array $query) { $isDuplicate = $query['duplicate'] === true; + $firstNonSystemLine = ''; + foreach ($query['trace'] as $index => &$line) { // simplify file and line if (isset($line['file'])) { @@ -143,6 +145,11 @@ public function display(): array $line['file'] = '[internal function]'; } + // find the first trace line that does not originate from `system/` + if ($firstNonSystemLine === '' && strpos($line['file'], 'SYSTEMPATH') === false) { + $firstNonSystemLine = $line['file']; + } + // simplify function call if (isset($line['class'])) { $line['function'] = $line['class'] . $line['type'] . $line['function']; @@ -162,20 +169,6 @@ public function display(): array $line['index'] = $indexPadded . str_repeat(chr(0xC2) . chr(0xA0), 4); } - // remove the caller trace which is duplicated as the last item - array_pop($query['trace']); - - // Find the first line that doesn't include `system` in the backtrace - $firstNonSystemLine = ''; - - foreach ($query['trace'] as $line) { - if (strpos($line['file'], 'SYSTEMPATH') === false) { - $firstNonSystemLine = $line['file']; - - break; - } - } - return [ 'hover' => $isDuplicate ? 'This query was called more than once.' : '', 'class' => $isDuplicate ? 'duplicate' : '',