sql_optimizer 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/app/controllers/sql_optimizer/sql_optimizer_controller.rb +41 -0
- data/app/views/sql_optimizer/{index.slim → sql_optimizer/index.slim} +0 -0
- data/config/routes.rb +4 -0
- data/lib/sql_optimizer/version.rb +1 -1
- metadata +4 -3
- data/app/controllers/sql_optimizer_controller.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98f4e6c24efdd74f36b07bc8175a32b992d7e07eb35c28e84e8eae1fafb7aa20
|
4
|
+
data.tar.gz: 52231b5e378a4f704ca173323d32ff03317ee580f056975881f888932119f720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7d071f42f074416a89665010826539c710566a40922b810e6573b478fefdcfb9c0e05310cdf91e2dcacf1cdf77d89d0f10cdc6bb8b421994c69f30945c5ff25
|
7
|
+
data.tar.gz: 1c4088e1753590a7d23ab8db29147d11b288f62796560b91a49efbf20aee68e05761cd7c2e5a7c6467fc53af567d3609fd9b048d3495ddbfc9db4ce19f26decf
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# SqlOptimizer
|
2
2
|
|
3
|
+
**This gem I use for my diploma, it isn't perfect, so I don't recommend to use it. In the future maybe I'll improve it.**
|
4
|
+
|
3
5
|
SqlOptimizer this is a gem for query optimization in your app. You can use two our method to check you query: `anayle` and `check_n_plus_one`. This is not so much, but we'll add more in the future. Also you can visit [localhost:3000/sql_optimizer](http://localhost:3000/sql_optimizer) to see information about queries in your app.
|
4
6
|
|
5
7
|
## Installation
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module SqlOptimizer
|
2
|
+
|
3
|
+
class SqlOptimizerController < ::ApplicationController
|
4
|
+
|
5
|
+
layout false
|
6
|
+
|
7
|
+
# GET /sql_optimizer
|
8
|
+
def index
|
9
|
+
@query_logs = QueryLog.where.not(source: nil)
|
10
|
+
@popular_queries = @query_logs.group_by(&:query).sort_by { |_, val| val.size }.last(3)
|
11
|
+
@max_query = @query_logs.order(duration: :desc).first
|
12
|
+
@min_query = @query_logs.order(:duration).first
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /graph
|
16
|
+
def graph
|
17
|
+
@query_logs = QueryLog.where.not(source: nil)
|
18
|
+
render json: collect_graph.to_json
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def collect_graph
|
24
|
+
@query_logs.group_by(&:query).first(10).map.with_index do |query, i|
|
25
|
+
durations = query[1].map(&:duration)
|
26
|
+
avg_time = durations.reduce(:+) / durations.size.to_f
|
27
|
+
{
|
28
|
+
index: i,
|
29
|
+
avg_time: avg_time.round(2),
|
30
|
+
data: {
|
31
|
+
query: query[1].first.query,
|
32
|
+
name: query[1].first.source,
|
33
|
+
size: query[1].size
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
File without changes
|
data/config/routes.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Korchma
|
@@ -68,10 +68,11 @@ files:
|
|
68
68
|
- LICENSE.txt
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
|
-
- app/controllers/sql_optimizer_controller.rb
|
72
|
-
- app/views/sql_optimizer/index.slim
|
71
|
+
- app/controllers/sql_optimizer/sql_optimizer_controller.rb
|
72
|
+
- app/views/sql_optimizer/sql_optimizer/index.slim
|
73
73
|
- bin/console
|
74
74
|
- bin/setup
|
75
|
+
- config/routes.rb
|
75
76
|
- lib/generators/sql_optimizer_generator.rb
|
76
77
|
- lib/sql_optimizer.rb
|
77
78
|
- lib/sql_optimizer/analyze.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
class SqlOptimizerController < ApplicationController
|
2
|
-
|
3
|
-
layout false
|
4
|
-
|
5
|
-
def index
|
6
|
-
@query_logs = QueryLog.where.not(source: nil)
|
7
|
-
@popular_queries = @query_logs.group_by(&:query).sort_by { |_, val| val.size }.last(3)
|
8
|
-
@max_query = @query_logs.order(duration: :desc).first
|
9
|
-
@min_query = @query_logs.order(:duration).first
|
10
|
-
end
|
11
|
-
|
12
|
-
def graph
|
13
|
-
@query_logs = QueryLog.where.not(source: nil)
|
14
|
-
render json: collect_graph.to_json
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def collect_graph
|
20
|
-
@query_logs.group_by(&:query).first(10).map.with_index do |query, i|
|
21
|
-
durations = query[1].map(&:duration)
|
22
|
-
avg_time = durations.reduce(:+) / durations.size.to_f
|
23
|
-
{
|
24
|
-
index: i,
|
25
|
-
avg_time: avg_time.round(2),
|
26
|
-
data: {
|
27
|
-
query: query[1].first.query,
|
28
|
-
name: query[1].first.source,
|
29
|
-
size: query[1].size
|
30
|
-
}
|
31
|
-
}
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|