bullet_instructure 4.0.5 → 4.14.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +27 -1
- data/CHANGELOG.md +44 -2
- data/Gemfile.mongoid +0 -2
- data/Gemfile.mongoid-2.4 +2 -4
- data/Gemfile.mongoid-2.5 +2 -4
- data/Gemfile.mongoid-2.6 +1 -3
- data/Gemfile.mongoid-2.7 +2 -4
- data/Gemfile.mongoid-2.8 +2 -4
- data/Gemfile.mongoid-3.0 +2 -4
- data/Gemfile.mongoid-3.1 +2 -4
- data/Gemfile.mongoid-4.0 +2 -4
- data/Gemfile.rails-3.0 +1 -3
- data/Gemfile.rails-3.1 +1 -3
- data/Gemfile.rails-3.2 +1 -3
- data/Gemfile.rails-4.0 +1 -3
- data/Gemfile.rails-4.1 +1 -3
- data/Gemfile.rails-4.2 +17 -0
- data/README.md +55 -43
- data/bullet_instructure.gemspec +2 -1
- data/lib/bullet/active_record3.rb +68 -34
- data/lib/bullet/active_record3x.rb +60 -32
- data/lib/bullet/active_record4.rb +57 -39
- data/lib/bullet/active_record41.rb +83 -42
- data/lib/bullet/active_record42.rb +195 -0
- data/lib/bullet/dependency.rb +6 -0
- data/lib/bullet/detector/association.rb +23 -17
- data/lib/bullet/detector/counter_cache.rb +16 -16
- data/lib/bullet/detector/n_plus_one_query.rb +43 -30
- data/lib/bullet/detector/unused_eager_loading.rb +2 -2
- data/lib/bullet/ext/object.rb +6 -2
- data/lib/bullet/notification/base.rb +17 -18
- data/lib/bullet/notification/n_plus_one_query.rb +6 -4
- data/lib/bullet/notification/unused_eager_loading.rb +1 -1
- data/lib/bullet/rack.rb +21 -14
- data/lib/bullet/version.rb +2 -2
- data/lib/bullet.rb +18 -10
- data/spec/bullet/detector/counter_cache_spec.rb +8 -8
- data/spec/bullet/detector/n_plus_one_query_spec.rb +27 -27
- data/spec/bullet/ext/object_spec.rb +14 -0
- data/spec/bullet/notification/base_spec.rb +30 -18
- data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +1 -1
- data/spec/bullet/rack_spec.rb +3 -3
- data/spec/bullet_spec.rb +2 -2
- data/spec/integration/active_record3/association_spec.rb +22 -2
- data/spec/integration/active_record4/association_spec.rb +47 -2
- data/spec/models/category.rb +5 -2
- data/spec/models/comment.rb +2 -0
- data/spec/models/post.rb +8 -3
- data/spec/models/reply.rb +3 -0
- data/spec/models/submission.rb +1 -1
- data/spec/spec_helper.rb +4 -4
- data/spec/support/sqlite_seed.rb +14 -6
- data/test.sh +1 -0
- data/update.sh +14 -0
- metadata +26 -9
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 386728c2453beb337c1e0870abbfc8349caa5486
|
4
|
+
data.tar.gz: 59afaf0d90531cf32716444bdff369c03f94726d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b5cb202734160f6311a1a681d7028337fb70282e9ca0a910817d28d718641e4585f488d47f7b996cc1528a9c1ef34e4c9f9496c7f56877ab8403e1e354b7798
|
7
|
+
data.tar.gz: f1e29ce313199b9dc756807f420ef85a19023337640b2c4ac24758d84e90ad734f37d0a6f8f25fe15f6a1d1fb9f8507c84488f6081d7d78d17849bdfaf62f518
|
data/.travis.yml
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
3
|
+
- 2.0
|
4
|
+
- 2.1
|
5
|
+
- 2.2
|
4
6
|
gemfile:
|
7
|
+
- Gemfile.rails-4.2
|
5
8
|
- Gemfile.rails-4.1
|
6
9
|
- Gemfile.rails-4.0
|
7
10
|
- Gemfile.rails-3.2
|
8
11
|
- Gemfile.rails-3.1
|
9
12
|
- Gemfile.rails-3.0
|
13
|
+
- Gemfile.mongoid-4.0
|
10
14
|
- Gemfile.mongoid-3.1
|
11
15
|
- Gemfile.mongoid-3.0
|
12
16
|
- Gemfile.mongoid-2.8
|
@@ -18,3 +22,25 @@ env:
|
|
18
22
|
- DB=sqlite
|
19
23
|
services:
|
20
24
|
- mongodb
|
25
|
+
matrix:
|
26
|
+
exclude:
|
27
|
+
- rvm: 2.2
|
28
|
+
gemfile: Gemfile.rails-3.0
|
29
|
+
- rvm: 2.2
|
30
|
+
gemfile: Gemfile.rails-3.1
|
31
|
+
- rvm: 2.2
|
32
|
+
gemfile: Gemfile.rails-3.2
|
33
|
+
- rvm: 2.2
|
34
|
+
gemfile: Gemfile.mongoid-3.1
|
35
|
+
- rvm: 2.2
|
36
|
+
gemfile: Gemfile.mongoid-3.0
|
37
|
+
- rvm: 2.2
|
38
|
+
gemfile: Gemfile.mongoid-2.8
|
39
|
+
- rvm: 2.2
|
40
|
+
gemfile: Gemfile.mongoid-2.7
|
41
|
+
- rvm: 2.2
|
42
|
+
gemfile: Gemfile.mongoid-2.6
|
43
|
+
- rvm: 2.2
|
44
|
+
gemfile: Gemfile.mongoid-2.5
|
45
|
+
- rvm: 2.2
|
46
|
+
gemfile: Gemfile.mongoid-2.4
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,52 @@
|
|
1
1
|
# Next Release
|
2
2
|
|
3
|
-
## 4.
|
3
|
+
## 4.14.6
|
4
4
|
|
5
|
-
*
|
5
|
+
* Fix false positive with `belongs_to` -> `belongs_to` for active\_record 4.2
|
6
|
+
* Activate active\_record hacks only when Bullet already start
|
7
|
+
|
8
|
+
## 4.14.5
|
9
|
+
|
10
|
+
* Don't execute query when running `to_sql`
|
11
|
+
* Send backtrace to `uniform_notifier`
|
12
|
+
* Fix sse response check
|
13
|
+
* Dynamically delegate available notifiers to UniformNotifier
|
14
|
+
|
15
|
+
## 4.14.4
|
16
|
+
|
17
|
+
* Fix false N + 1 warnings on Rails 4.2
|
18
|
+
|
19
|
+
## 4.14.3
|
20
|
+
|
21
|
+
* Fix false positive on create
|
22
|
+
|
23
|
+
## 4.14.2
|
24
|
+
|
25
|
+
* Hotfix nil object when `add_impossible_object`
|
26
|
+
|
27
|
+
## 4.14.1
|
28
|
+
|
29
|
+
* Fix `has_one` then `has_many` associations in rails 4.2
|
30
|
+
* Append js and dom to html body in proper position
|
31
|
+
|
32
|
+
## 4.14.0 (10/03/2014)
|
33
|
+
|
34
|
+
* Support rails 4.2
|
35
|
+
* Polish notification output
|
36
|
+
* Fix warning: `*' interpreted as argument prefix
|
37
|
+
|
38
|
+
## 4.13.0 (07/19/2014)
|
39
|
+
|
40
|
+
* Support include? call on ar associations
|
41
|
+
|
42
|
+
## 4.12.0 (07/13/2014)
|
43
|
+
|
44
|
+
* Fix false n+1 queries caused by inversed objects.
|
45
|
+
* Replace .id with .primary_key_value
|
6
46
|
* Rename bullet_ar_key to bullet_key
|
7
47
|
* Fix rails sse detect
|
48
|
+
* Fix bullet using in test environment
|
49
|
+
* Memoize whoami
|
8
50
|
|
9
51
|
## 4.11.0 (06/24/2014)
|
10
52
|
|
data/Gemfile.mongoid
CHANGED
data/Gemfile.mongoid-2.4
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.2.
|
5
|
+
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'mongoid', '~> 2.4.
|
8
|
+
gem 'mongoid', '~> 2.4.0'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.mongoid-2.5
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.2.
|
5
|
+
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'mongoid', '~> 2.5.
|
8
|
+
gem 'mongoid', '~> 2.5.0'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.mongoid-2.6
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.2.
|
5
|
+
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
8
|
gem 'mongoid', '~> 2.6.0'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.mongoid-2.7
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.2.
|
5
|
+
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'mongoid', '~> 2.7.
|
8
|
+
gem 'mongoid', '~> 2.7.0'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.mongoid-2.8
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.2'
|
5
|
+
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'mongoid', '~> 2.8'
|
8
|
+
gem 'mongoid', '~> 2.8.0'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.mongoid-3.0
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.2.
|
5
|
+
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'mongoid', '~> 3.0.
|
8
|
+
gem 'mongoid', '~> 3.0.0'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.mongoid-3.1
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.2.
|
5
|
+
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'mongoid', '~> 3.1.
|
8
|
+
gem 'mongoid', '~> 3.1.0'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.mongoid-4.0
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 4.0.
|
5
|
+
gem 'rails', '~> 4.0.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
-
gem 'mongoid', '~> 4.0.0
|
8
|
+
gem 'mongoid', '~> 4.0.0'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.rails-3.0
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.0.
|
5
|
+
gem 'rails', '~> 3.0.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
8
|
gem 'activerecord-import'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.rails-3.1
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.1.
|
5
|
+
gem 'rails', '~> 3.1.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
8
|
gem 'activerecord-import'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.rails-3.2
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 3.2.
|
5
|
+
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
8
|
gem 'activerecord-import'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.rails-4.0
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 4.0.
|
5
|
+
gem 'rails', '~> 4.0.0'
|
6
6
|
gem 'sqlite3', platforms: [:ruby]
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
8
|
gem 'activerecord-import'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.rails-4.1
CHANGED
@@ -2,14 +2,12 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rails', '~> 4.1.
|
5
|
+
gem 'rails', '~> 4.1.0'
|
6
6
|
gem 'sqlite3'
|
7
7
|
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
8
|
gem 'activerecord-import'
|
9
9
|
|
10
10
|
gem "rspec"
|
11
|
-
gem "guard"
|
12
|
-
gem "guard-rspec"
|
13
11
|
|
14
12
|
gem 'coveralls', require: false
|
15
13
|
|
data/Gemfile.rails-4.2
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'rails', '~> 4.2.0'
|
6
|
+
gem 'sqlite3'
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
8
|
+
gem 'activerecord-import'
|
9
|
+
|
10
|
+
gem "rspec"
|
11
|
+
|
12
|
+
gem 'coveralls', require: false
|
13
|
+
|
14
|
+
platforms :rbx do
|
15
|
+
gem 'rubysl', '~> 2.0'
|
16
|
+
gem 'rubinius-developer_tools'
|
17
|
+
end
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Best practice is to use Bullet in development mode or custom mode (staging, prof
|
|
12
12
|
|
13
13
|
Bullet gem now supports **activerecord** >= 3.0 and **mongoid** >= 2.4.1.
|
14
14
|
|
15
|
-
If you use
|
15
|
+
If you use activerecord 2.x, please use bullet <= 4.5.0
|
16
16
|
|
17
17
|
## External Introduction
|
18
18
|
|
@@ -53,42 +53,55 @@ config.after_initialize do
|
|
53
53
|
:receiver => 'your_account@jabber.org',
|
54
54
|
:show_online_status => true }
|
55
55
|
Bullet.rails_logger = true
|
56
|
+
Bullet.honeybadger = true
|
56
57
|
Bullet.bugsnag = true
|
57
58
|
Bullet.airbrake = true
|
59
|
+
Bullet.rollbar = true
|
58
60
|
Bullet.add_footer = true
|
59
61
|
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
|
62
|
+
Bullet.slack = { webhook_url: 'http://some.slack.url', foo: 'bar' }
|
60
63
|
end
|
61
64
|
```
|
62
65
|
|
63
|
-
The notifier of
|
66
|
+
The notifier of Bullet is a wrap of [uniform_notifier](https://github.com/flyerhzm/uniform_notifier)
|
64
67
|
|
65
68
|
The code above will enable all seven of the Bullet notification systems:
|
66
69
|
* `Bullet.enable`: enable Bullet gem, otherwise do nothing
|
67
70
|
* `Bullet.alert`: pop up a JavaScript alert in the browser
|
68
71
|
* `Bullet.bullet_logger`: log to the Bullet log file (Rails.root/log/bullet.log)
|
69
72
|
* `Bullet.rails_logger`: add warnings directly to the Rails log
|
73
|
+
* `Bullet.honeybadger`: add notifications to Honeybadger
|
74
|
+
* `Bullet.bugsnag`: add notifications to bugsnag
|
70
75
|
* `Bullet.airbrake`: add notifications to airbrake
|
76
|
+
* `Bullet.rollbar`: add notifications to rollbar
|
71
77
|
* `Bullet.console`: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
|
72
78
|
* `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
|
73
|
-
* `Bullet.xmpp`: send XMPP/Jabber notifications to the receiver indicated. Note that the code will currently not handle the adding of contacts, so you will need to make both accounts indicated know each other manually before you will receive any notifications. If you restart the development server frequently, the 'coming online' sound for the
|
79
|
+
* `Bullet.xmpp`: send XMPP/Jabber notifications to the receiver indicated. Note that the code will currently not handle the adding of contacts, so you will need to make both accounts indicated know each other manually before you will receive any notifications. If you restart the development server frequently, the 'coming online' sound for the Bullet account may start to annoy - in this case set :show_online_status to false; you will still get notifications, but the Bullet account won't announce it's online status anymore.
|
74
80
|
* `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
|
75
81
|
* `Bullet.add_footer`: adds the details in the bottom left corner of the page
|
76
82
|
* `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
|
83
|
+
* `Bullet.slack`: add notifications to slack
|
77
84
|
|
78
|
-
Bullet also allows you to disable
|
79
|
-
and counter_cache detectors respectively.
|
85
|
+
Bullet also allows you to disable any of its detectors.
|
80
86
|
|
81
87
|
```ruby
|
82
|
-
|
88
|
+
# Each of these settings defaults to true
|
89
|
+
|
90
|
+
# Detect N+1 queries
|
91
|
+
Bullet.n_plus_one_query_enable = false
|
92
|
+
|
93
|
+
# Detect eager-loaded associations which are not used
|
83
94
|
Bullet.unused_eager_loading_enable = false
|
84
|
-
|
95
|
+
|
96
|
+
# Detect unnecessary COUNT queries which could be avoided
|
97
|
+
# with a counter_cache
|
98
|
+
Bullet.counter_cache_enable = false
|
85
99
|
```
|
86
100
|
|
87
101
|
## Whitelist
|
88
102
|
|
89
|
-
Sometimes
|
90
|
-
|
91
|
-
that you can't fix, you can add whitelist to bullet
|
103
|
+
Sometimes Bullet may notify you of query problems you don't care to fix, or
|
104
|
+
which come from outside your code. You can whitelist these to ignore them:
|
92
105
|
|
93
106
|
```ruby
|
94
107
|
Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Post", :association => :comments
|
@@ -136,24 +149,25 @@ see [https://github.com/flyerhzm/uniform_notifier](https://github.com/flyerhzm/u
|
|
136
149
|
|
137
150
|
## Important
|
138
151
|
|
139
|
-
If you find
|
152
|
+
If you find Bullet does not work for you, *please disable your browser's cache*.
|
140
153
|
|
141
154
|
## Advanced
|
142
155
|
|
143
156
|
### Profile a job
|
144
157
|
|
145
|
-
The
|
158
|
+
The Bullet gem uses rack middleware to profile requests. If you want to use Bullet without an http server, like to profile a job, you can use use profile method and fetch warnings
|
146
159
|
|
147
160
|
```ruby
|
148
161
|
Bullet.profile do
|
149
162
|
# do anything
|
163
|
+
|
164
|
+
warnings = Bullet.warnings
|
150
165
|
end
|
151
|
-
warnings = Bullet.warnings
|
152
166
|
```
|
153
167
|
|
154
168
|
### Work with sinatra
|
155
169
|
|
156
|
-
Configure and use
|
170
|
+
Configure and use `Bullet::Rack`
|
157
171
|
|
158
172
|
```ruby
|
159
173
|
configure :development do
|
@@ -165,7 +179,7 @@ end
|
|
165
179
|
|
166
180
|
### Run in tests
|
167
181
|
|
168
|
-
First you need to enable
|
182
|
+
First you need to enable Bullet in test environment.
|
169
183
|
|
170
184
|
```ruby
|
171
185
|
# config/environments/test.rb
|
@@ -176,7 +190,7 @@ config.after_initialize do
|
|
176
190
|
end
|
177
191
|
```
|
178
192
|
|
179
|
-
Then wrap each test in
|
193
|
+
Then wrap each test in Bullet api.
|
180
194
|
|
181
195
|
```ruby
|
182
196
|
# spec/spec_helper.rb
|
@@ -194,18 +208,18 @@ end
|
|
194
208
|
|
195
209
|
## Debug Mode
|
196
210
|
|
197
|
-
Bullet outputs some details info, to enable debug mode, set
|
198
|
-
env.
|
211
|
+
Bullet outputs some details info, to enable debug mode, set
|
212
|
+
`BULLET_DEBUG=true` env.
|
199
213
|
|
200
214
|
## Contributors
|
201
215
|
|
202
216
|
[https://github.com/flyerhzm/bullet/contributors](https://github.com/flyerhzm/bullet/contributors)
|
203
217
|
|
204
|
-
##
|
218
|
+
## Demo
|
205
219
|
|
206
|
-
Bullet is designed to function as you browse through your application in development.
|
220
|
+
Bullet is designed to function as you browse through your application in development. To see it in action, follow these steps to create, detect, and fix example query problems.
|
207
221
|
|
208
|
-
1\.
|
222
|
+
1\. Create an example application
|
209
223
|
|
210
224
|
```
|
211
225
|
$ rails new test_bullet
|
@@ -215,7 +229,7 @@ $ rails g scaffold comment name:string post_id:integer
|
|
215
229
|
$ bundle exec rake db:migrate
|
216
230
|
```
|
217
231
|
|
218
|
-
2\.
|
232
|
+
2\. Change `app/model/post.rb` and `app/model/comment.rb`
|
219
233
|
|
220
234
|
```ruby
|
221
235
|
class Post < ActiveRecord::Base
|
@@ -227,7 +241,7 @@ class Comment < ActiveRecord::Base
|
|
227
241
|
end
|
228
242
|
```
|
229
243
|
|
230
|
-
3\.
|
244
|
+
3\. Go to `rails c` and execute
|
231
245
|
|
232
246
|
```ruby
|
233
247
|
post1 = Post.create(:name => 'first')
|
@@ -238,7 +252,7 @@ post2.comments.create(:name => 'third')
|
|
238
252
|
post2.comments.create(:name => 'fourth')
|
239
253
|
```
|
240
254
|
|
241
|
-
4\.
|
255
|
+
4\. Change the `app/views/posts/index.html.erb` to produce a N+1 query
|
242
256
|
|
243
257
|
```
|
244
258
|
<% @posts.each do |post| %>
|
@@ -252,7 +266,7 @@ post2.comments.create(:name => 'fourth')
|
|
252
266
|
<% end %>
|
253
267
|
```
|
254
268
|
|
255
|
-
5\.
|
269
|
+
5\. Add the `bullet` gem to the `Gemfile`
|
256
270
|
|
257
271
|
```ruby
|
258
272
|
gem "bullet"
|
@@ -264,7 +278,7 @@ And run
|
|
264
278
|
bundle install
|
265
279
|
```
|
266
280
|
|
267
|
-
6\. enable the
|
281
|
+
6\. enable the Bullet gem in development, add a line to
|
268
282
|
`config/environments/development.rb`
|
269
283
|
|
270
284
|
```ruby
|
@@ -279,13 +293,13 @@ config.after_initialize do
|
|
279
293
|
end
|
280
294
|
```
|
281
295
|
|
282
|
-
7\.
|
296
|
+
7\. Start the server
|
283
297
|
|
284
298
|
```
|
285
299
|
$ rails s
|
286
300
|
```
|
287
301
|
|
288
|
-
8\.
|
302
|
+
8\. Visit `http://localhost:3000/posts` in browser, and you will see a popup alert box that says
|
289
303
|
|
290
304
|
```
|
291
305
|
The request has unused preload associations as follows:
|
@@ -294,7 +308,7 @@ The request has N+1 queries as follows:
|
|
294
308
|
model: Post => associations: [comment]
|
295
309
|
```
|
296
310
|
|
297
|
-
which means there is a N+1 query from
|
311
|
+
which means there is a N+1 query from the Post object to its Comment association.
|
298
312
|
|
299
313
|
In the meanwhile, there's a log appended into `log/bullet.log` file
|
300
314
|
|
@@ -309,7 +323,7 @@ In the meanwhile, there's a log appended into `log/bullet.log` file
|
|
309
323
|
/home/flyerhzm/Downloads/test_bullet/app/controllers/posts_controller.rb:7:in `index'
|
310
324
|
```
|
311
325
|
|
312
|
-
The generated
|
326
|
+
The generated SQL is:
|
313
327
|
|
314
328
|
```
|
315
329
|
Post Load (1.0ms) SELECT * FROM "posts"
|
@@ -317,8 +331,7 @@ Comment Load (0.4ms) SELECT * FROM "comments" WHERE ("comments".post_id = 1)
|
|
317
331
|
Comment Load (0.3ms) SELECT * FROM "comments" WHERE ("comments".post_id = 2)
|
318
332
|
```
|
319
333
|
|
320
|
-
|
321
|
-
9\. fix the N+1 query, change `app/controllers/posts_controller.rb` file
|
334
|
+
9\. To fix the N+1 query, change `app/controllers/posts_controller.rb` file
|
322
335
|
|
323
336
|
```ruby
|
324
337
|
def index
|
@@ -331,18 +344,18 @@ def index
|
|
331
344
|
end
|
332
345
|
```
|
333
346
|
|
334
|
-
10\.
|
347
|
+
10\. Refresh `http://localhost:3000/posts`. Now there's no alert box and nothing new in the log.
|
335
348
|
|
336
|
-
The generated
|
349
|
+
The generated SQL is:
|
337
350
|
|
338
351
|
```
|
339
352
|
Post Load (0.5ms) SELECT * FROM "posts"
|
340
353
|
Comment Load (0.5ms) SELECT "comments".* FROM "comments" WHERE ("comments".post_id IN (1,2))
|
341
354
|
```
|
342
355
|
|
343
|
-
|
356
|
+
N+1 query fixed. Cool!
|
344
357
|
|
345
|
-
11\.
|
358
|
+
11\. Now simulate unused eager loading. Change
|
346
359
|
`app/controllers/posts_controller.rb` and
|
347
360
|
`app/views/posts/index.html.erb`
|
348
361
|
|
@@ -368,7 +381,7 @@ end
|
|
368
381
|
<% end %>
|
369
382
|
```
|
370
383
|
|
371
|
-
12\.
|
384
|
+
12\. Refresh `http://localhost:3000/posts`, and you will see a popup alert box that says
|
372
385
|
|
373
386
|
```
|
374
387
|
The request has unused preload associations as follows:
|
@@ -377,14 +390,14 @@ The request has N+1 queries as follows:
|
|
377
390
|
None
|
378
391
|
```
|
379
392
|
|
380
|
-
|
393
|
+
Meanwhile, there's a line appended to `log/bullet.log`
|
381
394
|
|
382
395
|
```
|
383
396
|
2009-08-25 21:13:22[INFO] Unused preload associations: PATH_INFO: /posts; model: Post => associations: [comments]·
|
384
397
|
Remove from your finder: :include => [:comments]
|
385
398
|
```
|
386
399
|
|
387
|
-
13\.
|
400
|
+
13\. Simulate counter_cache. Change `app/controllers/posts_controller.rb`
|
388
401
|
and `app/views/posts/index.html.erb`
|
389
402
|
|
390
403
|
```ruby
|
@@ -410,19 +423,18 @@ end
|
|
410
423
|
<% end %>
|
411
424
|
```
|
412
425
|
|
413
|
-
14\.
|
426
|
+
14\. Refresh `http://localhost:3000/posts`, then you will see a popup alert box that says
|
414
427
|
|
415
428
|
```
|
416
429
|
Need counter cache
|
417
430
|
Post => [:comments]
|
418
431
|
```
|
419
432
|
|
420
|
-
|
433
|
+
Meanwhile, there's a line appended to `log/bullet.log`
|
421
434
|
|
422
435
|
```
|
423
436
|
2009-09-11 10:07:10[INFO] Need Counter Cache
|
424
437
|
Post => [:comments]
|
425
438
|
```
|
426
439
|
|
427
|
-
|
428
|
-
Copyright (c) 2009 - 2014 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
440
|
+
Copyright (c) 2009 - 2015 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|