bullet 4.7.0 → 4.8.0
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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +17 -17
- data/CHANGELOG.md +15 -0
- data/Gemfile +9 -2
- data/Gemfile.mongoid-2.4 +22 -0
- data/Gemfile.mongoid-2.5 +22 -0
- data/Gemfile.mongoid-2.6 +22 -0
- data/Gemfile.mongoid-2.7 +22 -0
- data/Gemfile.mongoid-2.8 +22 -0
- data/Gemfile.mongoid-3.0 +22 -0
- data/Gemfile.mongoid-3.1 +22 -0
- data/Gemfile.rails-3.0 +21 -0
- data/Gemfile.rails-3.1 +21 -0
- data/Gemfile.rails-3.2 +21 -0
- data/Gemfile.rails-4.0 +21 -0
- data/{Gemfile.rails-3.0.20 → Gemfile.rails-4.1} +1 -1
- data/README.md +25 -24
- data/Rakefile +13 -6
- data/bullet.gemspec +1 -1
- data/lib/bullet/active_record41.rb +97 -0
- data/lib/bullet/dependency.rb +11 -1
- data/lib/bullet/mongoid4x.rb +1 -1
- data/lib/bullet/registry/base.rb +1 -1
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +1 -1
- data/spec/bullet/detector/association_spec.rb +8 -8
- data/spec/bullet/detector/base_spec.rb +1 -1
- data/spec/bullet/detector/counter_cache_spec.rb +12 -12
- data/spec/bullet/detector/n_plus_one_query_spec.rb +32 -32
- data/spec/bullet/detector/unused_eager_loading_spec.rb +18 -18
- data/spec/bullet/ext/object_spec.rb +2 -2
- data/spec/bullet/ext/string_spec.rb +2 -2
- data/spec/bullet/notification/base_spec.rb +19 -13
- data/spec/bullet/notification/counter_cache_spec.rb +2 -2
- data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +2 -2
- data/spec/bullet/notification_collector_spec.rb +4 -4
- data/spec/bullet/rack_spec.rb +21 -21
- data/spec/bullet/registry/association_spec.rb +3 -3
- data/spec/bullet/registry/base_spec.rb +6 -6
- data/spec/bullet/registry/object_spec.rb +2 -2
- data/spec/integration/active_record3/association_spec.rb +107 -107
- data/spec/integration/active_record4/association_spec.rb +105 -105
- data/spec/integration/counter_cache_spec.rb +4 -4
- data/spec/integration/mongoid/association_spec.rb +52 -52
- data/spec/spec_helper.rb +0 -1
- data/test.sh +12 -11
- metadata +27 -40
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/Gemfile.lock +0 -160
- data/Gemfile.mongoid-2.4.12 +0 -15
- data/Gemfile.mongoid-2.4.12.lock +0 -163
- data/Gemfile.mongoid-2.5.2 +0 -15
- data/Gemfile.mongoid-2.5.2.lock +0 -163
- data/Gemfile.mongoid-2.6.0 +0 -15
- data/Gemfile.mongoid-2.6.0.lock +0 -163
- data/Gemfile.mongoid-2.7.1 +0 -15
- data/Gemfile.mongoid-2.7.1.lock +0 -163
- data/Gemfile.mongoid-2.8.1 +0 -15
- data/Gemfile.mongoid-2.8.1.lock +0 -166
- data/Gemfile.mongoid-3.0.23 +0 -15
- data/Gemfile.mongoid-3.0.23.lock +0 -163
- data/Gemfile.mongoid-3.1.5 +0 -15
- data/Gemfile.mongoid-3.1.5.lock +0 -163
- data/Gemfile.mongoid.lock +0 -167
- data/Gemfile.rails-3.0.20.lock +0 -147
- data/Gemfile.rails-3.1.12 +0 -14
- data/Gemfile.rails-3.1.12.lock +0 -157
- data/Gemfile.rails-3.2.15 +0 -14
- data/Gemfile.rails-3.2.15.lock +0 -155
- data/Gemfile.rails-4.0.1 +0 -14
- data/Gemfile.rails-4.0.1.lock +0 -150
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ebb362baca8a029544d754fed872a09f7033377
|
|
4
|
+
data.tar.gz: f12124695713d21526305a4c381160048cdc93d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7aac621e2ddb3931bb385017401121641027980ebddf0d82d1b43c9a71040a7c2eba3af2c4cb7862d69f9c31c99ac1e124f6a60bd9be6e8388199c187effc98f
|
|
7
|
+
data.tar.gz: 721e946c60ebc8de7bd6c609abb90a9fd29c5c4df2ac275b8bb607e64cffcd86887fa7fc0c82fdd86303faf77d251519b49314dc9af1032131af039b9fd5f868
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
rvm:
|
|
3
|
-
- 2.
|
|
3
|
+
- 2.1.0
|
|
4
4
|
gemfile:
|
|
5
|
-
- Gemfile.rails-4.
|
|
6
|
-
- Gemfile.rails-
|
|
7
|
-
- Gemfile.rails-3.
|
|
8
|
-
- Gemfile.rails-3.
|
|
9
|
-
- Gemfile.
|
|
10
|
-
- Gemfile.mongoid-3.
|
|
11
|
-
- Gemfile.mongoid-
|
|
12
|
-
- Gemfile.mongoid-2.8
|
|
13
|
-
- Gemfile.mongoid-2.
|
|
14
|
-
- Gemfile.mongoid-2.
|
|
15
|
-
- Gemfile.mongoid-2.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
5
|
+
- Gemfile.rails-4.1
|
|
6
|
+
- Gemfile.rails-4.0
|
|
7
|
+
- Gemfile.rails-3.2
|
|
8
|
+
- Gemfile.rails-3.1
|
|
9
|
+
- Gemfile.rails-3.0
|
|
10
|
+
- Gemfile.mongoid-3.1
|
|
11
|
+
- Gemfile.mongoid-3.0
|
|
12
|
+
- Gemfile.mongoid-2.8
|
|
13
|
+
- Gemfile.mongoid-2.7
|
|
14
|
+
- Gemfile.mongoid-2.6
|
|
15
|
+
- Gemfile.mongoid-2.5
|
|
16
|
+
- Gemfile.mongoid-2.4
|
|
17
|
+
env:
|
|
18
|
+
- DB=sqlite
|
|
19
|
+
services:
|
|
20
|
+
- mongodb
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Next Release
|
|
2
2
|
|
|
3
|
+
## 4.8.0 (02/16/2014)
|
|
4
|
+
|
|
5
|
+
* Support rails 4.1.0.beta1
|
|
6
|
+
* Update specs to be RSepc 3.0 compatible
|
|
7
|
+
* Update latest minor version activerecord and mongoid on travis
|
|
8
|
+
|
|
9
|
+
## 4.7.0 (11/03/2013)
|
|
10
|
+
|
|
11
|
+
* Add coverall support
|
|
12
|
+
* Add helper to profile code outside a request
|
|
13
|
+
* Add activesupport dependency
|
|
14
|
+
* Add Bullet.raise notification
|
|
15
|
+
* Add Bullet.add_footer notification
|
|
16
|
+
* Fix activerecord4 warnings in test code
|
|
17
|
+
|
|
3
18
|
## 4.6.0 (04/18/2013)
|
|
4
19
|
|
|
5
20
|
* Fix Bullet::Rack to support sinatra
|
data/Gemfile
CHANGED
|
@@ -3,8 +3,10 @@ source "https://rubygems.org"
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
5
|
gem 'rails', github: 'rails/rails'
|
|
6
|
-
gem 'sqlite3'
|
|
7
|
-
gem '
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
8
10
|
gem 'activerecord-import'
|
|
9
11
|
|
|
10
12
|
gem "rspec"
|
|
@@ -12,3 +14,8 @@ gem "guard"
|
|
|
12
14
|
gem "guard-rspec"
|
|
13
15
|
|
|
14
16
|
gem 'coveralls', require: false
|
|
17
|
+
|
|
18
|
+
platforms :rbx do
|
|
19
|
+
gem 'rubysl', '~> 2.0'
|
|
20
|
+
gem 'rubinius-developer_tools'
|
|
21
|
+
end
|
data/Gemfile.mongoid-2.4
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.2.16'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
gem 'mongoid', '~> 2.4.12'
|
|
12
|
+
|
|
13
|
+
gem "rspec"
|
|
14
|
+
gem "guard"
|
|
15
|
+
gem "guard-rspec"
|
|
16
|
+
|
|
17
|
+
gem 'coveralls', require: false
|
|
18
|
+
|
|
19
|
+
platforms :rbx do
|
|
20
|
+
gem 'rubysl', '~> 2.0'
|
|
21
|
+
gem 'rubinius-developer_tools'
|
|
22
|
+
end
|
data/Gemfile.mongoid-2.5
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.2.16'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
gem 'mongoid', '~> 2.5.2'
|
|
12
|
+
|
|
13
|
+
gem "rspec"
|
|
14
|
+
gem "guard"
|
|
15
|
+
gem "guard-rspec"
|
|
16
|
+
|
|
17
|
+
gem 'coveralls', require: false
|
|
18
|
+
|
|
19
|
+
platforms :rbx do
|
|
20
|
+
gem 'rubysl', '~> 2.0'
|
|
21
|
+
gem 'rubinius-developer_tools'
|
|
22
|
+
end
|
data/Gemfile.mongoid-2.6
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.2.16'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
gem 'mongoid', '~> 2.6.0'
|
|
12
|
+
|
|
13
|
+
gem "rspec"
|
|
14
|
+
gem "guard"
|
|
15
|
+
gem "guard-rspec"
|
|
16
|
+
|
|
17
|
+
gem 'coveralls', require: false
|
|
18
|
+
|
|
19
|
+
platforms :rbx do
|
|
20
|
+
gem 'rubysl', '~> 2.0'
|
|
21
|
+
gem 'rubinius-developer_tools'
|
|
22
|
+
end
|
data/Gemfile.mongoid-2.7
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.2.16'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
gem 'mongoid', '~> 2.7.1'
|
|
12
|
+
|
|
13
|
+
gem "rspec"
|
|
14
|
+
gem "guard"
|
|
15
|
+
gem "guard-rspec"
|
|
16
|
+
|
|
17
|
+
gem 'coveralls', require: false
|
|
18
|
+
|
|
19
|
+
platforms :rbx do
|
|
20
|
+
gem 'rubysl', '~> 2.0'
|
|
21
|
+
gem 'rubinius-developer_tools'
|
|
22
|
+
end
|
data/Gemfile.mongoid-2.8
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.2'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
gem 'mongoid', '~> 2.8'
|
|
12
|
+
|
|
13
|
+
gem "rspec"
|
|
14
|
+
gem "guard"
|
|
15
|
+
gem "guard-rspec"
|
|
16
|
+
|
|
17
|
+
gem 'coveralls', require: false
|
|
18
|
+
|
|
19
|
+
platforms :rbx do
|
|
20
|
+
gem 'rubysl', '~> 2.0'
|
|
21
|
+
gem 'rubinius-developer_tools'
|
|
22
|
+
end
|
data/Gemfile.mongoid-3.0
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.2.16'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
gem 'mongoid', '~> 3.0.23'
|
|
12
|
+
|
|
13
|
+
gem "rspec"
|
|
14
|
+
gem "guard"
|
|
15
|
+
gem "guard-rspec"
|
|
16
|
+
|
|
17
|
+
gem 'coveralls', require: false
|
|
18
|
+
|
|
19
|
+
platforms :rbx do
|
|
20
|
+
gem 'rubysl', '~> 2.0'
|
|
21
|
+
gem 'rubinius-developer_tools'
|
|
22
|
+
end
|
data/Gemfile.mongoid-3.1
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.2.16'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
gem 'mongoid', '~> 3.1.6'
|
|
12
|
+
|
|
13
|
+
gem "rspec"
|
|
14
|
+
gem "guard"
|
|
15
|
+
gem "guard-rspec"
|
|
16
|
+
|
|
17
|
+
gem 'coveralls', require: false
|
|
18
|
+
|
|
19
|
+
platforms :rbx do
|
|
20
|
+
gem 'rubysl', '~> 2.0'
|
|
21
|
+
gem 'rubinius-developer_tools'
|
|
22
|
+
end
|
data/Gemfile.rails-3.0
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.0.20'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
|
|
12
|
+
gem "rspec"
|
|
13
|
+
gem "guard"
|
|
14
|
+
gem "guard-rspec"
|
|
15
|
+
|
|
16
|
+
gem 'coveralls', require: false
|
|
17
|
+
|
|
18
|
+
platforms :rbx do
|
|
19
|
+
gem 'rubysl', '~> 2.0'
|
|
20
|
+
gem 'rubinius-developer_tools'
|
|
21
|
+
end
|
data/Gemfile.rails-3.1
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.1.12'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
|
|
12
|
+
gem "rspec"
|
|
13
|
+
gem "guard"
|
|
14
|
+
gem "guard-rspec"
|
|
15
|
+
|
|
16
|
+
gem 'coveralls', require: false
|
|
17
|
+
|
|
18
|
+
platforms :rbx do
|
|
19
|
+
gem 'rubysl', '~> 2.0'
|
|
20
|
+
gem 'rubinius-developer_tools'
|
|
21
|
+
end
|
data/Gemfile.rails-3.2
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 3.2.15'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
|
|
12
|
+
gem "rspec"
|
|
13
|
+
gem "guard"
|
|
14
|
+
gem "guard-rspec"
|
|
15
|
+
|
|
16
|
+
gem 'coveralls', require: false
|
|
17
|
+
|
|
18
|
+
platforms :rbx do
|
|
19
|
+
gem 'rubysl', '~> 2.0'
|
|
20
|
+
gem 'rubinius-developer_tools'
|
|
21
|
+
end
|
data/Gemfile.rails-4.0
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'rails', '~> 4.0.1'
|
|
6
|
+
gem 'sqlite3', platforms: [:ruby]
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
|
|
8
|
+
gem 'mysql2', platforms: [:ruby]
|
|
9
|
+
gem 'activerecord-jdbcmysql-adapter', platforms: [:jruby]
|
|
10
|
+
gem 'activerecord-import'
|
|
11
|
+
|
|
12
|
+
gem "rspec"
|
|
13
|
+
gem "guard"
|
|
14
|
+
gem "guard-rspec"
|
|
15
|
+
|
|
16
|
+
gem 'coveralls', require: false
|
|
17
|
+
|
|
18
|
+
platforms :rbx do
|
|
19
|
+
gem 'rubysl', '~> 2.0'
|
|
20
|
+
gem 'rubinius-developer_tools'
|
|
21
|
+
end
|
data/README.md
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
[](http://badge.fury.io/rb/bullet)
|
|
4
4
|
[](http://travis-ci.org/flyerhzm/bullet)
|
|
5
5
|
[](https://coveralls.io/r/flyerhzm/bullet)
|
|
6
|
-
|
|
6
|
+
<a href="https://codeclimate.com/github/flyerhzm/bullet"><img src="https://codeclimate.com/github/flyerhzm/bullet.png" /></a>
|
|
7
7
|
[](http://coderwall.com/flyerhzm)
|
|
8
8
|
|
|
9
9
|
The Bullet gem is designed to help you increase your application's performance by reducing the number of queries it makes. It will watch your queries while you develop your application and notify you when you should add eager loading (N+1 queries), when you're using eager loading that isn't necessary and when you should use counter cache.
|
|
10
10
|
|
|
11
11
|
Best practice is to use Bullet in development mode or custom mode (staging, profile, etc.). The last thing you want is your clients getting alerts about how lazy you are.
|
|
12
12
|
|
|
13
|
-
Bullet gem now supports **activerecord**
|
|
13
|
+
Bullet gem now supports **activerecord** >= 3.0 and **mongoid** >= 2.4.1.
|
|
14
14
|
|
|
15
15
|
If you use activercord 2.x, please use bullet <= 4.5.0
|
|
16
16
|
|
|
@@ -27,7 +27,6 @@ You can install it as a gem:
|
|
|
27
27
|
|
|
28
28
|
```
|
|
29
29
|
gem install bullet
|
|
30
|
-
|
|
31
30
|
```
|
|
32
31
|
|
|
33
32
|
or add it into a Gemfile (Bundler):
|
|
@@ -138,40 +137,42 @@ If you find bullet does not work for you, *please disable your browser's cache*.
|
|
|
138
137
|
|
|
139
138
|
## Advanced
|
|
140
139
|
|
|
141
|
-
|
|
140
|
+
### Profile a job
|
|
141
|
+
|
|
142
|
+
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
|
|
142
143
|
|
|
143
144
|
```ruby
|
|
144
145
|
Bullet.profile do
|
|
145
|
-
#
|
|
146
|
+
# do anything
|
|
146
147
|
end
|
|
148
|
+
warnings = Bullet.warnings
|
|
147
149
|
```
|
|
148
150
|
|
|
149
|
-
|
|
151
|
+
### Run in tests
|
|
150
152
|
|
|
151
|
-
|
|
152
|
-
before(:each)
|
|
153
|
-
Bullet.start_request if Bullet.enable?
|
|
154
|
-
end
|
|
153
|
+
First you need to enable bullet in test environment.
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
Bullet.
|
|
155
|
+
```ruby
|
|
156
|
+
# config/environments/test.rb
|
|
157
|
+
config.after_initialize do
|
|
158
|
+
Bullet.enable = true
|
|
159
|
+
Bullet.bullet_logger = true
|
|
160
|
+
Bullet.raise = true # raise an error if n+1 query occurs
|
|
161
161
|
end
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
### API access
|
|
167
|
-
|
|
168
|
-
after `profile`, you can fetch warnings then do whatever you want
|
|
164
|
+
Then wrap each test in bullet api.
|
|
169
165
|
|
|
170
166
|
```ruby
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
# spec/spec_helper.rb
|
|
168
|
+
before(:each) do
|
|
169
|
+
Bullet.start_request if Bullet.enable?
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
after(:each) do
|
|
173
|
+
Bullet.perform_out_of_channel_notifications if Bullet.enable? && Bullet.notification?
|
|
174
|
+
Bullet.end_request if Bullet.enable?
|
|
173
175
|
end
|
|
174
|
-
warnings = Bullet.warnings
|
|
175
176
|
```
|
|
176
177
|
|
|
177
178
|
## Contributors
|
|
@@ -402,4 +403,4 @@ In the meanwhile, there's a log appended into `log/bullet.log` file.
|
|
|
402
403
|
```
|
|
403
404
|
|
|
404
405
|
|
|
405
|
-
Copyright (c) 2009 -
|
|
406
|
+
Copyright (c) 2009 - 2014 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
data/Rakefile
CHANGED
|
@@ -3,7 +3,6 @@ require "bundler"
|
|
|
3
3
|
Bundler.setup
|
|
4
4
|
|
|
5
5
|
require "rake"
|
|
6
|
-
require "rdoc/task"
|
|
7
6
|
require "rspec"
|
|
8
7
|
require "rspec/core/rake_task"
|
|
9
8
|
|
|
@@ -35,11 +34,19 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
|
|
|
35
34
|
spec.pattern = "spec/**/*_spec.rb"
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
rdoc
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
|
|
38
|
+
begin
|
|
39
|
+
require 'rdoc/task'
|
|
40
|
+
|
|
41
|
+
desc "Generate documentation for the plugin."
|
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
|
43
|
+
rdoc.rdoc_dir = "rdoc"
|
|
44
|
+
rdoc.title = "bullet #{Bullet::VERSION}"
|
|
45
|
+
rdoc.rdoc_files.include("README*")
|
|
46
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
|
47
|
+
end
|
|
48
|
+
rescue LoadError
|
|
49
|
+
puts 'RDocTask is not supported for this platform'
|
|
43
50
|
end
|
|
44
51
|
|
|
45
52
|
task :default => :spec
|
data/bullet.gemspec
CHANGED
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
|
16
16
|
s.required_rubygems_version = ">= 1.3.6"
|
|
17
17
|
|
|
18
18
|
s.add_dependency "activesupport"
|
|
19
|
-
s.add_dependency "uniform_notifier", ">= 1.
|
|
19
|
+
s.add_dependency "uniform_notifier", ">= 1.4.0"
|
|
20
20
|
|
|
21
21
|
s.files = `git ls-files`.split("\n")
|
|
22
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
module Bullet
|
|
2
|
+
module ActiveRecord
|
|
3
|
+
def self.enable
|
|
4
|
+
require 'active_record'
|
|
5
|
+
::ActiveRecord::Relation.class_eval do
|
|
6
|
+
alias_method :origin_to_a, :to_a
|
|
7
|
+
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
|
8
|
+
# if select only one object, then the only one object has impossible to cause N+1 query.
|
|
9
|
+
def to_a
|
|
10
|
+
records = origin_to_a
|
|
11
|
+
if records.first.class.name !~ /^HABTM_/
|
|
12
|
+
if records.size > 1
|
|
13
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
|
14
|
+
Bullet::Detector::CounterCache.add_possible_objects(records)
|
|
15
|
+
elsif records.size == 1
|
|
16
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
|
|
17
|
+
Bullet::Detector::CounterCache.add_impossible_object(records.first)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
records
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
::ActiveRecord::Associations::Preloader.class_eval do
|
|
25
|
+
alias_method :origin_preloaders_on, :preloaders_on
|
|
26
|
+
|
|
27
|
+
def preloaders_on(association, records, scope)
|
|
28
|
+
if records.first.class.name !~ /^HABTM_/
|
|
29
|
+
records.each do |record|
|
|
30
|
+
Bullet::Detector::Association.add_object_associations(record, association)
|
|
31
|
+
end
|
|
32
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
|
|
33
|
+
end
|
|
34
|
+
origin_preloaders_on(association, records, scope)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
::ActiveRecord::FinderMethods.class_eval do
|
|
39
|
+
# add includes in scope
|
|
40
|
+
alias_method :origin_find_with_associations, :find_with_associations
|
|
41
|
+
def find_with_associations
|
|
42
|
+
records = origin_find_with_associations
|
|
43
|
+
associations = (eager_load_values + includes_values).uniq
|
|
44
|
+
records.each do |record|
|
|
45
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
46
|
+
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
|
47
|
+
end
|
|
48
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
|
49
|
+
records
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
::ActiveRecord::Associations::JoinDependency.class_eval do
|
|
54
|
+
alias_method :origin_construct_model, :construct_model
|
|
55
|
+
# call join associations
|
|
56
|
+
def construct_model(record, node, row, model_cache, id, aliases)
|
|
57
|
+
associations = node.reflection.name
|
|
58
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
|
59
|
+
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
|
60
|
+
origin_construct_model(record, node, row, model_cache, id, aliases)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
::ActiveRecord::Associations::CollectionAssociation.class_eval do
|
|
65
|
+
# call one to many associations
|
|
66
|
+
alias_method :origin_load_target, :load_target
|
|
67
|
+
def load_target
|
|
68
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
|
|
69
|
+
origin_load_target
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
::ActiveRecord::Associations::SingularAssociation.class_eval do
|
|
74
|
+
# call has_one and belongs_to associations
|
|
75
|
+
alias_method :origin_reader, :reader
|
|
76
|
+
def reader(force_reload = false)
|
|
77
|
+
result = origin_reader(force_reload)
|
|
78
|
+
if @owner.class.name !~ /^HABTM_/
|
|
79
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
|
|
80
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
|
81
|
+
end
|
|
82
|
+
result
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
87
|
+
alias_method :origin_has_cached_counter?, :has_cached_counter?
|
|
88
|
+
|
|
89
|
+
def has_cached_counter?(reflection = reflection)
|
|
90
|
+
result = origin_has_cached_counter?(reflection)
|
|
91
|
+
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
|
|
92
|
+
result
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
data/lib/bullet/dependency.rb
CHANGED
|
@@ -18,8 +18,10 @@ module Bullet
|
|
|
18
18
|
'active_record3'
|
|
19
19
|
elsif active_record31? || active_record32?
|
|
20
20
|
'active_record3x'
|
|
21
|
-
elsif
|
|
21
|
+
elsif active_record40?
|
|
22
22
|
'active_record4'
|
|
23
|
+
elsif active_record41?
|
|
24
|
+
'active_record41'
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
27
|
end
|
|
@@ -56,6 +58,14 @@ module Bullet
|
|
|
56
58
|
active_record3? && ::ActiveRecord::VERSION::MINOR == 2
|
|
57
59
|
end
|
|
58
60
|
|
|
61
|
+
def active_record40?
|
|
62
|
+
active_record4? && ::ActiveRecord::VERSION::MINOR == 0
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def active_record41?
|
|
66
|
+
active_record4? && ::ActiveRecord::VERSION::MINOR == 1
|
|
67
|
+
end
|
|
68
|
+
|
|
59
69
|
def mongoid2x?
|
|
60
70
|
mongoid? && ::Mongoid::VERSION =~ /\A2\.[4-8]/
|
|
61
71
|
end
|
data/lib/bullet/mongoid4x.rb
CHANGED
|
@@ -44,7 +44,7 @@ module Bullet
|
|
|
44
44
|
alias_method :origin_set_relation, :set_relation
|
|
45
45
|
|
|
46
46
|
def set_relation(name, relation)
|
|
47
|
-
if relation && relation.
|
|
47
|
+
if relation && relation.relation_metadata.macro !~ /embed/
|
|
48
48
|
Bullet::Detector::NPlusOneQuery.call_association(self, name)
|
|
49
49
|
end
|
|
50
50
|
origin_set_relation(name, relation)
|
data/lib/bullet/registry/base.rb
CHANGED
data/lib/bullet/version.rb
CHANGED
data/lib/bullet.rb
CHANGED
|
@@ -66,7 +66,7 @@ module Bullet
|
|
|
66
66
|
|
|
67
67
|
def add_whitelist(options)
|
|
68
68
|
@whitelist[options[:type]][options[:class_name].classify] ||= []
|
|
69
|
-
@whitelist[options[:type]][options[:class_name].classify] << options[:association]
|
|
69
|
+
@whitelist[options[:type]][options[:class_name].classify] << options[:association]
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def get_whitelist_associations(type, class_name)
|