sql_optimizer 0.1.2 → 0.1.3

This diff has not been reviewed by any users.
Log in in order to be able to vote.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98f4e6c24efdd74f36b07bc8175a32b992d7e07eb35c28e84e8eae1fafb7aa20
4
- data.tar.gz: 52231b5e378a4f704ca173323d32ff03317ee580f056975881f888932119f720
3
+ metadata.gz: 575fa5b95bc8bfbba54f463ed2753ce63c04acc7fd4cad14acec35f4ce774086
4
+ data.tar.gz: f7439edbd9a1465a172bde51599265308114b3127f2649cc34b67af2afb2d875
5
5
  SHA512:
6
- metadata.gz: d7d071f42f074416a89665010826539c710566a40922b810e6573b478fefdcfb9c0e05310cdf91e2dcacf1cdf77d89d0f10cdc6bb8b421994c69f30945c5ff25
7
- data.tar.gz: 1c4088e1753590a7d23ab8db29147d11b288f62796560b91a49efbf20aee68e05761cd7c2e5a7c6467fc53af567d3609fd9b048d3495ddbfc9db4ce19f26decf
6
+ metadata.gz: 0b58712ab51595b818e4d74c148b29cdfd0ea83725a76352b13f6f55e04627a95cb5938fc1b90489e8d50566475da80058014b54cfa96dc4f22cc3af68f5a524
7
+ data.tar.gz: 61a0de99cf1ca80c832d9f7caa492a37075384fcdaf0aa87d4854599ad5047a34d0eb4b0f04b742881dfad40ff32e2c42e5d760c211da2ac92bf5903d64b5a13
@@ -1,41 +1,37 @@
1
- module SqlOptimizer
1
+ class SqlOptimizerController < ApplicationController
2
2
 
3
- class SqlOptimizerController < ::ApplicationController
3
+ layout false
4
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
5
+ # GET /sql_optimizer
6
+ def index
7
+ @query_logs = QueryLog.where.not(source: nil)
8
+ @popular_queries = @query_logs.group_by(&:query).sort_by { |_, val| val.size }.last(3)
9
+ @max_query = @query_logs.order(duration: :desc).first
10
+ @min_query = @query_logs.order(:duration).first
11
+ end
20
12
 
21
- private
13
+ # GET /graph
14
+ def graph
15
+ @query_logs = QueryLog.where.not(source: nil)
16
+ render json: collect_graph.to_json
17
+ end
22
18
 
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
- }
19
+ private
20
+
21
+ def collect_graph
22
+ @query_logs.group_by(&:query).first(10).map.with_index do |query, i|
23
+ durations = query[1].map(&:duration)
24
+ avg_time = durations.reduce(:+) / durations.size.to_f
25
+ {
26
+ index: i,
27
+ avg_time: avg_time.round(2),
28
+ data: {
29
+ query: query[1].first.query,
30
+ name: query[1].first.source,
31
+ size: query[1].size
35
32
  }
36
- end
33
+ }
37
34
  end
38
-
39
35
  end
40
36
 
41
37
  end
@@ -1,4 +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
+ # 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
@@ -5,6 +5,7 @@ class SqlOptimizerGenerator < Rails::Generators::Base
5
5
  migration_number = Dir.glob("#{Rails.root}/db/migrate/*").max_by { |name| name[/\d+/].to_i }[/\d+/].to_i + 1
6
6
  create_file "db/migrate/#{migration_number}_create_query_logs.rb", migration_content
7
7
  create_file 'app/models/query_log.rb', model_content
8
+ create_file 'app/controllers/sql_optimizer.rb', controller_content
8
9
  application(nil, env: :development) { initializer_content }
9
10
  route route_content
10
11
  rake 'db:migrate'
@@ -54,4 +55,46 @@ class SqlOptimizerGenerator < Rails::Generators::Base
54
55
  RUBY
55
56
  end
56
57
 
58
+ def controller_content
59
+ <<~RUBY
60
+ class SqlOptimizerController < ApplicationController
61
+
62
+ layout false
63
+
64
+ # GET /sql_optimizer
65
+ def index
66
+ @query_logs = QueryLog.where.not(source: nil)
67
+ @popular_queries = @query_logs.group_by(&:query).sort_by { |_, val| val.size }.last(3)
68
+ @max_query = @query_logs.order(duration: :desc).first
69
+ @min_query = @query_logs.order(:duration).first
70
+ end
71
+
72
+ # GET /graph
73
+ def graph
74
+ @query_logs = QueryLog.where.not(source: nil)
75
+ render json: collect_graph.to_json
76
+ end
77
+
78
+ private
79
+
80
+ def collect_graph
81
+ @query_logs.group_by(&:query).first(10).map.with_index do |query, i|
82
+ durations = query[1].map(&:duration)
83
+ avg_time = durations.reduce(:+) / durations.size.to_f
84
+ {
85
+ index: i,
86
+ avg_time: avg_time.round(2),
87
+ data: {
88
+ query: query[1].first.query,
89
+ name: query[1].first.source,
90
+ size: query[1].size
91
+ }
92
+ }
93
+ end
94
+ end
95
+
96
+ end
97
+ RUBY
98
+ end
99
+
57
100
  end
@@ -1,5 +1,5 @@
1
1
  module SqlOptimizer
2
2
 
3
- VERSION = '0.1.2'.freeze
3
+ VERSION = '0.1.3'.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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Korchma
@@ -69,7 +69,7 @@ files:
69
69
  - README.md
70
70
  - Rakefile
71
71
  - app/controllers/sql_optimizer/sql_optimizer_controller.rb
72
- - app/views/sql_optimizer/sql_optimizer/index.slim
72
+ - app/views/sql_optimizer/index.slim
73
73
  - bin/console
74
74
  - bin/setup
75
75
  - config/routes.rb