sql_optimizer 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '096f95c4b92b1cf43b3406da1dca462622ad9c0883528bec6b9b004c8574fb21'
4
- data.tar.gz: ee6ae051ca2eb5db5aa5751f33bfba62089b9a2347fbfb9864b3d461717aa3ed
3
+ metadata.gz: 98f4e6c24efdd74f36b07bc8175a32b992d7e07eb35c28e84e8eae1fafb7aa20
4
+ data.tar.gz: 52231b5e378a4f704ca173323d32ff03317ee580f056975881f888932119f720
5
5
  SHA512:
6
- metadata.gz: 570b079b36dc8cfc9a218c117dd6e13d21438589b57c99080f925067ac505c42c1f7b26a788214787c229db1f8caa68b2092a630af321aa8ccab4f661cef0472
7
- data.tar.gz: b844e1b144de765d464c64506c93e9e0a68989e10c4fb1cec4c5e2a4f5459a0cd95f73698be7c71dae57ce0d73236df2a769936279f4294b4c49a25a35c123c4
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
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ get 'sql_optimizer', to: 'sql_optimizer/sql_optimizer#index'
3
+ get 'graph', to: 'sql_optimizer/sql_optimizer#graph'
4
+ end
@@ -1,5 +1,5 @@
1
1
  module SqlOptimizer
2
2
 
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
 
5
5
  end
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.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