Skip to content

Commit 7640308

Browse files
committed
rename config file
1 parent ffda738 commit 7640308

File tree

2 files changed

+74
-16
lines changed

2 files changed

+74
-16
lines changed

config/sqd.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,70 @@
22

33
return [
44

5+
/*
6+
|--------------------------------------------------------------------------
7+
| Package state
8+
|--------------------------------------------------------------------------
9+
|
10+
| Determines whether query listening is enabled
11+
|
12+
*/
13+
514
'enabled' => (bool) env('SQD_ENABLED', true),
615

716
'code' => [
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Maximum number of queries when processing the controller method
21+
|--------------------------------------------------------------------------
22+
|
23+
| If your method executes more queries than this
24+
| value the notification will be received
25+
|
26+
*/
27+
828
'max_queries' => (int) env('SQD_CODE_MAX_QUERIES', 50),
29+
30+
/*
31+
|--------------------------------------------------------------------------
32+
| Maximum execution time of the controller method (in ms)
33+
|--------------------------------------------------------------------------
34+
|
35+
| If your method takes longer than this value to complete
36+
| the notification will be received
37+
|
38+
*/
39+
940
'max_time' => (int) env('SQD_CODE_MAX_TIME', 1000),
1041
],
1142

1243
'query' => [
44+
45+
/*
46+
|--------------------------------------------------------------------------
47+
| Queries with bindings
48+
|--------------------------------------------------------------------------
49+
|
50+
| If true then bindings will be applied to queries in notification.
51+
| Example (if true): "select * from users where name = John" instead of
52+
| "select * from users where name = ?"
53+
|
54+
*/
55+
1356
'with_bindings' => (bool) env('SQD_QUERY_BINDINGS', true),
14-
'max_time' => (int) env('SQD_QUERY_MAX_TIME', 50),
57+
58+
/*
59+
|--------------------------------------------------------------------------
60+
| Maximum execution time for each query in DB (in ms)
61+
|--------------------------------------------------------------------------
62+
|
63+
| If at least one query exceeds this value
64+
| you will receive a notification
65+
|
66+
*/
67+
68+
'max_time' => (int) env('SQD_QUERY_MAX_TIME', 0),
1569
],
1670

1771
];

src/Http/Middleware/SlowQueryDetectorMiddleware.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function handle($request, Closure $next)
2626

2727
\DB::listen(function ($query) {
2828
$this->queriesCount++;
29-
if ($query->time > config('slow-query-detector.query.max_time')) {
29+
if ($query->time > config('sqd.query.max_time')) {
3030
$this->heavyQueryCount++;
3131
if ($query->time > $this->heaviestQueryTime) {
3232
$this->heaviestQueryTime = $query->time;
@@ -48,29 +48,33 @@ public function handle($request, Closure $next)
4848

4949
protected function needNotify()
5050
{
51-
return $this->queriesCount > config('slow-query-detector.code.max_queries')
52-
|| $this->executionTime > config('slow-query-detector.code.max_time')
53-
|| $this->heaviestQueryTime > config('slow-query-detector.query.max_time');
51+
return $this->queriesCount > config('sqd.code.max_queries')
52+
|| $this->executionTime > config('sqd.code.max_time')
53+
|| $this->heaviestQueryTime > config('sqd.query.max_time');
5454
}
5555

5656
protected function notify($request)
5757
{
58-
app('log')->critical(print_r([
59-
'Execution Time' => $this->executionTime,
60-
'Queries Count' => $this->queriesCount,
61-
'Heavy Queries Count' => $this->heavyQueryCount,
62-
'Full URL' => $request->fullUrl(),
63-
'Action' => $request->route()->getActionName(),
64-
'Heaviest Query' => [
65-
'Query' => $this->heaviestQuery,
66-
'Time' => $this->heaviestQueryTime,
58+
$data = [
59+
'SQD' => [
60+
'Execution Time' => $this->executionTime . ' ms.',
61+
'Queries Count' => $this->queriesCount,
62+
'Heavy Queries Count' => $this->heavyQueryCount,
63+
'Full URL' => $request->fullUrl(),
64+
'Action' => $request->route()->getActionName(),
65+
'Heaviest Query' => [
66+
'Query' => $this->heaviestQuery,
67+
'Time' => $this->heaviestQueryTime . ' ms.',
68+
]
6769
]
68-
], true));
70+
];
71+
72+
app('log')->critical(print_r($data, true));
6973
}
7074

7175
protected function getQuery($query)
7276
{
73-
return config('slow-query-detector.query.with_bindings')
77+
return config('sqd.query.with_bindings')
7478
? Str::replaceArray('?', $query->bindings, $query->sql)
7579
: $query->sql;
7680
}

0 commit comments

Comments
 (0)