Error when query time is above 999 ms
cyrildewit opened this issue · 4 comments
- PHP: v7.3.1
- Laravel: v7.1.3
- Telescope: v3.1.1
- Telescope Toolbar: v1.2.2
Hi,
I have a query that takes around 5247.76 ms. For this reason, I wanted to see if I can optimize it using this toolbar.
The toolbar was unfortunately showing the following error message:
An 500 error occurred while loading the Telescope Toolbar. Make sure you configured/installed Telescope correctly.
When I looked into the response of the made request by this toolbar, I saw the following error (shortened):
"message": "A non well formed numeric value encountered (View: /home/vagrant/GitHub/eloquent-viewable-demo-app/vendor/fruitcake/laravel-telescope-toolbar/resources/views/collectors/queries.blade.php)",
"exception": "Facade\\Ignition\\Exceptions\\ViewException",
"file": "/home/vagrant/GitHub/eloquent-viewable-demo-app/vendor/fruitcake/laravel-telescope-toolbar/src/../resources/views/collectors/queries.blade.php",
"line": 21,
Line 21:
$query_time += $query->content['time'] ?? 0;
I decided to look at the value of $query->content['time']
and it returned 5,247.76
.
This is where the problem lays. PHP can't cast it, because it doesn't understand the format.
Looking into the source code of Telescope, I saw this line in the QueryWatcher
:
'time' => number_format($time, 2),
I'm currently thinking about a solution but it may take a while.
Thanks for creating and maintaining this package!
Perhaps just (float) str_replace(',', '', $duration)
? https://3v4l.org/nhUcm
Looks good to me.
Can you make a PR?
Yeah sure.