query_diet 0.5.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +86 -0
  3. data/lib/query_diet/active_record_ext.rb +6 -8
  4. data/lib/query_diet/rack/reset_logger.rb +2 -2
  5. data/lib/query_diet/version.rb +1 -1
  6. data/lib/query_diet/widget.rb +20 -5
  7. metadata +22 -172
  8. data/.gitignore +0 -4
  9. data/README.rdoc +0 -56
  10. data/Rakefile +0 -44
  11. data/query_diet.gemspec +0 -22
  12. data/spec/rails-2.3/Gemfile +0 -9
  13. data/spec/rails-2.3/Gemfile.lock +0 -60
  14. data/spec/rails-2.3/Rakefile +0 -11
  15. data/spec/rails-2.3/app_root/config/boot.rb +0 -114
  16. data/spec/rails-2.3/app_root/config/database.yml +0 -4
  17. data/spec/rails-2.3/app_root/config/environment.rb +0 -14
  18. data/spec/rails-2.3/app_root/config/environments/test.rb +0 -0
  19. data/spec/rails-2.3/app_root/config/routes.rb +0 -4
  20. data/spec/rails-2.3/app_root/log/.gitignore +0 -1
  21. data/spec/rails-2.3/spec.opts +0 -5
  22. data/spec/rails-2.3/spec_helper.rb +0 -27
  23. data/spec/rails-3.0/.rspec +0 -2
  24. data/spec/rails-3.0/Gemfile +0 -9
  25. data/spec/rails-3.0/Gemfile.lock +0 -116
  26. data/spec/rails-3.0/Rakefile +0 -10
  27. data/spec/rails-3.0/app_root/.gitignore +0 -4
  28. data/spec/rails-3.0/app_root/config/application.rb +0 -32
  29. data/spec/rails-3.0/app_root/config/boot.rb +0 -13
  30. data/spec/rails-3.0/app_root/config/database.yml +0 -4
  31. data/spec/rails-3.0/app_root/config/environment.rb +0 -5
  32. data/spec/rails-3.0/app_root/config/environments/test.rb +0 -35
  33. data/spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb +0 -7
  34. data/spec/rails-3.0/app_root/config/initializers/inflections.rb +0 -10
  35. data/spec/rails-3.0/app_root/config/initializers/mime_types.rb +0 -5
  36. data/spec/rails-3.0/app_root/config/initializers/secret_token.rb +0 -7
  37. data/spec/rails-3.0/app_root/config/initializers/session_store.rb +0 -8
  38. data/spec/rails-3.0/app_root/config/routes.rb +0 -58
  39. data/spec/rails-3.0/app_root/lib/tasks/.gitkeep +0 -0
  40. data/spec/rails-3.0/app_root/log/.gitkeep +0 -0
  41. data/spec/rails-3.0/app_root/script/rails +0 -6
  42. data/spec/rails-3.0/rcov.opts +0 -2
  43. data/spec/rails-3.0/spec_helper.rb +0 -31
  44. data/spec/rails-3.2/.rspec +0 -2
  45. data/spec/rails-3.2/Gemfile +0 -10
  46. data/spec/rails-3.2/Gemfile.lock +0 -127
  47. data/spec/rails-3.2/Rakefile +0 -10
  48. data/spec/rails-3.2/app_root/.gitignore +0 -4
  49. data/spec/rails-3.2/app_root/config/application.rb +0 -32
  50. data/spec/rails-3.2/app_root/config/boot.rb +0 -13
  51. data/spec/rails-3.2/app_root/config/database.yml +0 -4
  52. data/spec/rails-3.2/app_root/config/environment.rb +0 -5
  53. data/spec/rails-3.2/app_root/config/environments/test.rb +0 -35
  54. data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +0 -7
  55. data/spec/rails-3.2/app_root/config/initializers/inflections.rb +0 -10
  56. data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +0 -5
  57. data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +0 -7
  58. data/spec/rails-3.2/app_root/config/initializers/session_store.rb +0 -8
  59. data/spec/rails-3.2/app_root/config/routes.rb +0 -58
  60. data/spec/rails-3.2/app_root/log/.gitignore +0 -1
  61. data/spec/rails-3.2/rcov.opts +0 -2
  62. data/spec/rails-3.2/spec_helper.rb +0 -31
  63. data/spec/shared/app_root/app/controllers/application_controller.rb +0 -2
  64. data/spec/shared/app_root/app/controllers/query_diet_controller.rb +0 -13
  65. data/spec/shared/app_root/app/models/movie.rb +0 -3
  66. data/spec/shared/app_root/app/views/layouts/screen.html.erb +0 -7
  67. data/spec/shared/app_root/app/views/query_diet/no_query.html.erb +0 -3
  68. data/spec/shared/app_root/app/views/query_diet/two_queries.html.erb +0 -3
  69. data/spec/shared/app_root/db/.gitignore +0 -1
  70. data/spec/shared/app_root/db/migrate/001_create_movies.rb +0 -14
  71. data/spec/shared/query_diet/helpers/widget_spec.rb +0 -32
  72. data/spec/shared/query_diet/integration/widget_spec.rb +0 -23
  73. data/spec/shared/query_diet/logger_spec.rb +0 -91
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 17f9c2961a95f7d7c70c35ae50bc6f0e659bc3c746ddf519c65448cc9faefa98
4
+ data.tar.gz: 7f76be36042170e1e8d5aff0b066d552f9fff66f2ea5d31bffee3924e5e21368
5
+ SHA512:
6
+ metadata.gz: 17e90e9a4ec095f1c333f719226ec938d8f058526bdf14c2d731842cf1322057d3d14f35b279e0dd62b86600366b4318e8206852e104a71a25a0bc9dc323f309
7
+ data.tar.gz: 2c7d0bac77d92987974d9229535bff8b438e520c2b00ae71ef37206eef6d2d114ffa07515e5b67af5b78a08a103738fd588ae5c64f8f80dc00f373950dd1e583
@@ -0,0 +1,86 @@
1
+ Query Diet [![Build Status](https://travis-ci.org/makandra/query_diet.svg?branch=master)](https://travis-ci.org/makandra/query_diet)
2
+ ==========
3
+
4
+ Query Diet counts the number of database queries for the last request and *subtly* displays it in the upper right corner of your screen.
5
+ The display turns red if too many queries are run, or if they take too long.
6
+ This is useful to prevent [N + 1 queries](http://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations) from creeping into your code.
7
+
8
+ This is Query Diet being happy about 3 requests taking 66ms:
9
+
10
+ ![](http://blog.makandra.com/images/articles/2010-06-25-solving-the-n-1-query-problem-with-query-diet/query_diet_happy.png)
11
+
12
+ This is Query Diet being angry about 103 requests taking 164ms:
13
+
14
+ ![](http://blog.makandra.com/images/articles/2010-06-25-solving-the-n-1-query-problem-with-query-diet/query_diet_angry.png)
15
+
16
+
17
+ Installation
18
+ ------------
19
+
20
+ Add it to your Gemfile with
21
+
22
+ ```Ruby
23
+ gem 'query_diet', group: :development
24
+ ```
25
+
26
+ Now add the widget to your application layout, like
27
+
28
+ ```Erb
29
+ # app/views/layout/application.html.erb
30
+ # ...
31
+ <body>
32
+ <%= query_diet_widget if Rails.env.development? %>
33
+ <%= yield %>
34
+ </body>
35
+ ```
36
+
37
+ We recommend you only use the gem with the development environment.
38
+
39
+ ### Changing warning thresholds
40
+
41
+ You can define when the counter turns into a red warning. The default threshold is 8 queries and 5000 miliseconds.
42
+ To change the default, simply pass them to the `query_diet_widget` helper:
43
+
44
+ ```Erb
45
+ <%= query_diet_widget(:bad_count => 4, :bad_time => 2000) %>
46
+ ```
47
+
48
+ ### Content Security Policy
49
+
50
+ You can pass whether to use a nonce for style and script tags.
51
+ Note that the key must be a symbol like in the example below, otherwise it defaults to `false`.
52
+
53
+ ```Erb
54
+ <%= query_diet_widget(:nonce => true) if Rails.env.development? %>
55
+ ```
56
+
57
+ In your content security policy initializer of the project you should set the nonce to those directives:
58
+ ```Erb
59
+ Rails.application.config.content_security_policy_nonce_directives = %w[script-src style-src]
60
+ ```
61
+
62
+ When you do not want to use a nonce, but use a style tag, for example, you could use `unsafe_inline`:
63
+ ```Erb
64
+ Rails.application.config.content_security_policy do |policy|
65
+ policy.style_src :self, :unsafe_inline
66
+ ```
67
+
68
+ ### Rails compatibility
69
+
70
+ The gem is tested to work with Rails 3.2+ and Ruby 2.0+.
71
+
72
+ For Rails 2.3 and Ruby 1.8.7 support, use a version < 0.6.
73
+
74
+
75
+ Credits
76
+ -------
77
+
78
+ [Henning Koch](https://github.com/henning-koch)
79
+
80
+ [Tobias Kraze](https://github.com/kratob)
81
+
82
+ [makandra.com](http://makandra.com/)
83
+
84
+ [gem-session.com](http://gem-session.com/)
85
+
86
+ [Michael Grosser](https://github.com/grosser)
@@ -1,11 +1,9 @@
1
- ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
2
-
3
- def log_with_query_diet(query, *args, &block)
4
- QueryDiet::Logger.log(query) do
5
- log_without_query_diet(query, *args, &block)
1
+ module QueryDiet
2
+ module ActiveRecordExt
3
+ def log(query, *)
4
+ QueryDiet::Logger.log(query) { super }
6
5
  end
7
6
  end
8
-
9
- alias_method_chain :log, :query_diet
10
-
11
7
  end
8
+
9
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:prepend, QueryDiet::ActiveRecordExt)
@@ -18,9 +18,9 @@ end
18
18
  if defined?(Rails::Railtie)
19
19
  class QueryDiet::Railtie < Rails::Railtie
20
20
  initializer 'query_diet.insert_middleware' do |app|
21
- app.config.middleware.use 'QueryDiet::Rack::ResetLogger'
21
+ app.config.middleware.use QueryDiet::Rack::ResetLogger
22
22
  end
23
23
  end
24
24
  else
25
- ActionController::Dispatcher.middleware.use('QueryDiet::Rack::ResetLogger')
25
+ ActionController::Dispatcher.middleware.use(QueryDiet::Rack::ResetLogger)
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module QueryDiet
2
- VERSION = '0.5.3'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -2,16 +2,16 @@ module QueryDiet
2
2
  module Widget
3
3
  class << self
4
4
 
5
- def css
5
+ def css(nonce_attribute)
6
6
  <<-EOF
7
- <style type="text/css"><!--
7
+ <style type="text/css"#{nonce_attribute}><!--
8
8
  div#query_diet {
9
9
  position: absolute;
10
10
  top: 0;
11
11
  right: 0;
12
12
  background-color: black;
13
13
  color: white;
14
- z-index: 999;
14
+ z-index: 99999;
15
15
  padding: 4px 6px;
16
16
  font: normal bold 12px/12px Arial, sans-serif;
17
17
  cursor: pointer;
@@ -31,9 +31,19 @@ module QueryDiet
31
31
  EOF
32
32
  end
33
33
 
34
+ def js(nonce_attribute)
35
+ <<-EOF
36
+ <script type="text/javascript"#{nonce_attribute}>
37
+ document.getElementById("query_diet").addEventListener("click", function() {
38
+ this.parentNode.removeChild(this);
39
+ });
40
+ </script>
41
+ EOF
42
+ end
43
+
34
44
  def html(options)
35
45
  <<-EOF
36
- <div id="query_diet" class="#{QueryDiet::Logger.bad?(options) ? 'bad' : 'good' }" onclick="this.parentNode.removeChild(this);">
46
+ <div id="query_diet" class="#{QueryDiet::Logger.bad?(options) ? 'bad' : 'good' }">
37
47
  #{QueryDiet::Logger.count} / #{QueryDiet::Logger.time}ms
38
48
  </div>
39
49
  EOF
@@ -43,7 +53,12 @@ module QueryDiet
43
53
 
44
54
  module Helper
45
55
  def query_diet_widget(options = {})
46
- html = Widget.css + Widget.html(options)
56
+ default_html_options = {:nonce => false}
57
+ options = options.reverse_merge(default_html_options)
58
+
59
+ nonce_attribute = options.fetch(:nonce) ? " nonce=\"#{content_security_policy_nonce}\"" : ''
60
+
61
+ html = Widget.css(nonce_attribute) + Widget.html(options) + Widget.js(nonce_attribute)
47
62
  html.respond_to?(:html_safe) ? html.html_safe : html
48
63
  end
49
64
  end
metadata CHANGED
@@ -1,201 +1,51 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: query_diet
3
- version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 3
10
- version: 0.5.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Henning Koch
14
8
  - Tobias Kraze
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2014-10-20 00:00:00 +02:00
20
- default_executable:
12
+ date: 2020-09-24 00:00:00.000000000 Z
21
13
  dependencies: []
22
-
23
14
  description: Rails database query counter that stays out of your way
24
15
  email: github@makandra.de
25
16
  executables: []
26
-
27
17
  extensions: []
28
-
29
18
  extra_rdoc_files: []
30
-
31
- files:
32
- - .gitignore
19
+ files:
33
20
  - MIT-LICENSE
34
- - README.rdoc
35
- - Rakefile
21
+ - README.md
36
22
  - lib/query_diet.rb
37
23
  - lib/query_diet/active_record_ext.rb
38
24
  - lib/query_diet/logger.rb
39
25
  - lib/query_diet/rack/reset_logger.rb
40
26
  - lib/query_diet/version.rb
41
27
  - lib/query_diet/widget.rb
42
- - query_diet.gemspec
43
- - spec/rails-2.3/Gemfile
44
- - spec/rails-2.3/Gemfile.lock
45
- - spec/rails-2.3/Rakefile
46
- - spec/rails-2.3/app_root/config/boot.rb
47
- - spec/rails-2.3/app_root/config/database.yml
48
- - spec/rails-2.3/app_root/config/environment.rb
49
- - spec/rails-2.3/app_root/config/environments/test.rb
50
- - spec/rails-2.3/app_root/config/routes.rb
51
- - spec/rails-2.3/app_root/log/.gitignore
52
- - spec/rails-2.3/spec.opts
53
- - spec/rails-2.3/spec_helper.rb
54
- - spec/rails-3.0/.rspec
55
- - spec/rails-3.0/Gemfile
56
- - spec/rails-3.0/Gemfile.lock
57
- - spec/rails-3.0/Rakefile
58
- - spec/rails-3.0/app_root/.gitignore
59
- - spec/rails-3.0/app_root/config/application.rb
60
- - spec/rails-3.0/app_root/config/boot.rb
61
- - spec/rails-3.0/app_root/config/database.yml
62
- - spec/rails-3.0/app_root/config/environment.rb
63
- - spec/rails-3.0/app_root/config/environments/test.rb
64
- - spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb
65
- - spec/rails-3.0/app_root/config/initializers/inflections.rb
66
- - spec/rails-3.0/app_root/config/initializers/mime_types.rb
67
- - spec/rails-3.0/app_root/config/initializers/secret_token.rb
68
- - spec/rails-3.0/app_root/config/initializers/session_store.rb
69
- - spec/rails-3.0/app_root/config/routes.rb
70
- - spec/rails-3.0/app_root/lib/tasks/.gitkeep
71
- - spec/rails-3.0/app_root/log/.gitkeep
72
- - spec/rails-3.0/app_root/script/rails
73
- - spec/rails-3.0/rcov.opts
74
- - spec/rails-3.0/spec_helper.rb
75
- - spec/rails-3.2/.rspec
76
- - spec/rails-3.2/Gemfile
77
- - spec/rails-3.2/Gemfile.lock
78
- - spec/rails-3.2/Rakefile
79
- - spec/rails-3.2/app_root/.gitignore
80
- - spec/rails-3.2/app_root/config/application.rb
81
- - spec/rails-3.2/app_root/config/boot.rb
82
- - spec/rails-3.2/app_root/config/database.yml
83
- - spec/rails-3.2/app_root/config/environment.rb
84
- - spec/rails-3.2/app_root/config/environments/test.rb
85
- - spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb
86
- - spec/rails-3.2/app_root/config/initializers/inflections.rb
87
- - spec/rails-3.2/app_root/config/initializers/mime_types.rb
88
- - spec/rails-3.2/app_root/config/initializers/secret_token.rb
89
- - spec/rails-3.2/app_root/config/initializers/session_store.rb
90
- - spec/rails-3.2/app_root/config/routes.rb
91
- - spec/rails-3.2/app_root/log/.gitignore
92
- - spec/rails-3.2/rcov.opts
93
- - spec/rails-3.2/spec_helper.rb
94
- - spec/shared/app_root/app/controllers/application_controller.rb
95
- - spec/shared/app_root/app/controllers/query_diet_controller.rb
96
- - spec/shared/app_root/app/models/movie.rb
97
- - spec/shared/app_root/app/views/layouts/screen.html.erb
98
- - spec/shared/app_root/app/views/query_diet/no_query.html.erb
99
- - spec/shared/app_root/app/views/query_diet/two_queries.html.erb
100
- - spec/shared/app_root/db/.gitignore
101
- - spec/shared/app_root/db/migrate/001_create_movies.rb
102
- - spec/shared/query_diet/helpers/widget_spec.rb
103
- - spec/shared/query_diet/integration/widget_spec.rb
104
- - spec/shared/query_diet/logger_spec.rb
105
- has_rdoc: true
106
28
  homepage: https://github.com/makandra/query_diet
107
- licenses:
29
+ licenses:
108
30
  - MIT
109
- post_install_message: Remember to put <%= query_diet_widget if Rails.env.development? %> into your app layout.
31
+ metadata: {}
32
+ post_install_message:
110
33
  rdoc_options: []
111
-
112
- require_paths:
34
+ require_paths:
113
35
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
117
38
  - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- version: "0"
123
- required_rubygems_version: !ruby/object:Gem::Requirement
124
- none: false
125
- requirements:
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
126
43
  - - ">="
127
- - !ruby/object:Gem::Version
128
- hash: 3
129
- segments:
130
- - 0
131
- version: "0"
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
132
46
  requirements: []
133
-
134
- rubyforge_project:
135
- rubygems_version: 1.3.9.5
47
+ rubygems_version: 3.1.3
136
48
  signing_key:
137
- specification_version: 3
49
+ specification_version: 4
138
50
  summary: Rails database query counter that stays out of your way
139
- test_files:
140
- - spec/rails-2.3/Gemfile
141
- - spec/rails-2.3/Gemfile.lock
142
- - spec/rails-2.3/Rakefile
143
- - spec/rails-2.3/app_root/config/boot.rb
144
- - spec/rails-2.3/app_root/config/database.yml
145
- - spec/rails-2.3/app_root/config/environment.rb
146
- - spec/rails-2.3/app_root/config/environments/test.rb
147
- - spec/rails-2.3/app_root/config/routes.rb
148
- - spec/rails-2.3/app_root/log/.gitignore
149
- - spec/rails-2.3/spec.opts
150
- - spec/rails-2.3/spec_helper.rb
151
- - spec/rails-3.0/.rspec
152
- - spec/rails-3.0/Gemfile
153
- - spec/rails-3.0/Gemfile.lock
154
- - spec/rails-3.0/Rakefile
155
- - spec/rails-3.0/app_root/.gitignore
156
- - spec/rails-3.0/app_root/config/application.rb
157
- - spec/rails-3.0/app_root/config/boot.rb
158
- - spec/rails-3.0/app_root/config/database.yml
159
- - spec/rails-3.0/app_root/config/environment.rb
160
- - spec/rails-3.0/app_root/config/environments/test.rb
161
- - spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb
162
- - spec/rails-3.0/app_root/config/initializers/inflections.rb
163
- - spec/rails-3.0/app_root/config/initializers/mime_types.rb
164
- - spec/rails-3.0/app_root/config/initializers/secret_token.rb
165
- - spec/rails-3.0/app_root/config/initializers/session_store.rb
166
- - spec/rails-3.0/app_root/config/routes.rb
167
- - spec/rails-3.0/app_root/lib/tasks/.gitkeep
168
- - spec/rails-3.0/app_root/log/.gitkeep
169
- - spec/rails-3.0/app_root/script/rails
170
- - spec/rails-3.0/rcov.opts
171
- - spec/rails-3.0/spec_helper.rb
172
- - spec/rails-3.2/.rspec
173
- - spec/rails-3.2/Gemfile
174
- - spec/rails-3.2/Gemfile.lock
175
- - spec/rails-3.2/Rakefile
176
- - spec/rails-3.2/app_root/.gitignore
177
- - spec/rails-3.2/app_root/config/application.rb
178
- - spec/rails-3.2/app_root/config/boot.rb
179
- - spec/rails-3.2/app_root/config/database.yml
180
- - spec/rails-3.2/app_root/config/environment.rb
181
- - spec/rails-3.2/app_root/config/environments/test.rb
182
- - spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb
183
- - spec/rails-3.2/app_root/config/initializers/inflections.rb
184
- - spec/rails-3.2/app_root/config/initializers/mime_types.rb
185
- - spec/rails-3.2/app_root/config/initializers/secret_token.rb
186
- - spec/rails-3.2/app_root/config/initializers/session_store.rb
187
- - spec/rails-3.2/app_root/config/routes.rb
188
- - spec/rails-3.2/app_root/log/.gitignore
189
- - spec/rails-3.2/rcov.opts
190
- - spec/rails-3.2/spec_helper.rb
191
- - spec/shared/app_root/app/controllers/application_controller.rb
192
- - spec/shared/app_root/app/controllers/query_diet_controller.rb
193
- - spec/shared/app_root/app/models/movie.rb
194
- - spec/shared/app_root/app/views/layouts/screen.html.erb
195
- - spec/shared/app_root/app/views/query_diet/no_query.html.erb
196
- - spec/shared/app_root/app/views/query_diet/two_queries.html.erb
197
- - spec/shared/app_root/db/.gitignore
198
- - spec/shared/app_root/db/migrate/001_create_movies.rb
199
- - spec/shared/query_diet/helpers/widget_spec.rb
200
- - spec/shared/query_diet/integration/widget_spec.rb
201
- - spec/shared/query_diet/logger_spec.rb
51
+ test_files: []
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- doc
2
- pkg
3
- *.gem
4
- .idea
@@ -1,56 +0,0 @@
1
- = Query Diet
2
-
3
- Query Diet counts the number of database queries for the last request and *subtly* displays it in the upper right corner of your screen.
4
- The display turns red if too many queries are run, or if they take too long.
5
- This is useful to prevent {N + 1 queries}[http://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations] from creeping into your code.
6
-
7
- This is Query Diet being happy about 3 requests taking 66ms:
8
-
9
- http://blog.makandra.com/images/articles/2010-06-25-solving-the-n-1-query-problem-with-query-diet/query_diet_happy.png
10
-
11
- This is Query Diet being angry about 103 requests taking 164ms:
12
-
13
- http://blog.makandra.com/images/articles/2010-06-25-solving-the-n-1-query-problem-with-query-diet/query_diet_angry.png
14
-
15
- == Installation
16
-
17
- Add it to your Gemfile with
18
- gem 'query_diet'
19
-
20
-
21
- Now add the widget to your application layout, like
22
-
23
- # app/views/layout/application.html.erb
24
- # ...
25
- <body>
26
- <%= query_diet_widget if Rails.env.development? %>
27
- <%= yield %>
28
- </body>
29
-
30
-
31
- We recommend you only use the gem with the development environment.
32
-
33
- == Changing warning thresholds
34
-
35
- You can define when the counter turns into a red warning. The default threshold is 8 queries and 5000 miliseconds.
36
- To change the default, simply pass them to the `query_diet_widget` helper:
37
-
38
- <%= query_diet_widget(:bad_count => 4, :bad_time => 2000) %>
39
-
40
-
41
- == Rails compatibility
42
-
43
- The gem is tested to work with Rails 2.3, Rails 3.0 and Rails 3.2.
44
-
45
-
46
- === Credits
47
-
48
- Henning Koch
49
-
50
- Tobias Kraze
51
-
52
- {makandra.com}[http://makandra.com/]
53
-
54
- {gem-session.com}[http://gem-session.com/]
55
-
56
- {Michael Grosser}[https://github.com/grosser]