bullet 4.14.3 → 4.14.10

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +28 -1
  3. data/CHANGELOG.md +38 -2
  4. data/Gemfile.mongoid +0 -2
  5. data/Gemfile.mongoid-2.4 +0 -2
  6. data/Gemfile.mongoid-2.5 +0 -2
  7. data/Gemfile.mongoid-2.6 +0 -2
  8. data/Gemfile.mongoid-2.7 +0 -2
  9. data/Gemfile.mongoid-2.8 +0 -2
  10. data/Gemfile.mongoid-3.0 +0 -2
  11. data/Gemfile.mongoid-3.1 +0 -2
  12. data/Gemfile.mongoid-4.0 +0 -2
  13. data/Gemfile.mongoid-5.0 +17 -0
  14. data/Gemfile.rails-3.1 +0 -2
  15. data/Gemfile.rails-3.2 +0 -2
  16. data/Gemfile.rails-4.0 +0 -2
  17. data/Gemfile.rails-4.1 +0 -2
  18. data/Gemfile.rails-4.2 +0 -2
  19. data/README.md +27 -1
  20. data/bullet.gemspec +1 -1
  21. data/lib/bullet/active_record3.rb +65 -35
  22. data/lib/bullet/active_record3x.rb +54 -32
  23. data/lib/bullet/active_record4.rb +61 -31
  24. data/lib/bullet/active_record41.rb +63 -32
  25. data/lib/bullet/active_record42.rb +105 -43
  26. data/lib/bullet/dependency.rb +6 -0
  27. data/lib/bullet/detector/association.rb +16 -16
  28. data/lib/bullet/detector/counter_cache.rb +13 -13
  29. data/lib/bullet/detector/n_plus_one_query.rb +30 -27
  30. data/lib/bullet/detector/unused_eager_loading.rb +1 -1
  31. data/lib/bullet/ext/object.rb +3 -1
  32. data/lib/bullet/mongoid5x.rb +56 -0
  33. data/lib/bullet/notification/n_plus_one_query.rb +6 -0
  34. data/lib/bullet/rack.rb +4 -6
  35. data/lib/bullet/version.rb +1 -1
  36. data/lib/bullet.rb +23 -10
  37. data/spec/bullet/detector/counter_cache_spec.rb +8 -8
  38. data/spec/bullet/detector/n_plus_one_query_spec.rb +27 -27
  39. data/spec/bullet/ext/object_spec.rb +6 -0
  40. data/spec/bullet/notification/base_spec.rb +2 -2
  41. data/spec/bullet/rack_spec.rb +2 -2
  42. data/spec/bullet_spec.rb +47 -0
  43. data/spec/integration/active_record3/association_spec.rb +11 -2
  44. data/spec/integration/active_record4/association_spec.rb +32 -2
  45. data/spec/integration/counter_cache_spec.rb +8 -1
  46. data/spec/spec_helper.rb +1 -0
  47. data/spec/support/mongo_seed.rb +13 -0
  48. data/test.sh +1 -0
  49. data/update.sh +1 -0
  50. metadata +9 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbe02316f8b3e0b61718c940420f189423c3f5f0
4
- data.tar.gz: 93db165a6618fb9c470081013e4b2f5fe002c602
3
+ metadata.gz: 262911eb5bb5cc6577489084cca4c06042ec466b
4
+ data.tar.gz: 6aa0f9e1403c8f36cac9375b451880a82c9561cd
5
5
  SHA512:
6
- metadata.gz: 6c9ec0b4e3c23e6de5f59f74cb9378f5db7c32a448a42d4304b2399c3762308bab649dffc7f86bd04aaf175946391df9658994a1a190fb2a64fb8ec5bd21dbb3
7
- data.tar.gz: 47451dec206f2d05aaa11466d8f6c063bbb9e3e9c03929d7dc8867b11e77be6871ee6a58f1f2b52435db3bb6854e913228dc9b310bf7dd78f5b968de5f042932
6
+ metadata.gz: 99c812cc4085c2e9763ba05564f98b4b3ab9027820932eb70d09060fbfb69071d38d8d844b67d29dc167ad04983e8133fa5727b426122d9a4e0f3b9c55e9bd3b
7
+ data.tar.gz: d1316bb72c9228fb4b7746795d528506eb472d1bd906424c17bbb5a3adcdd995e75bcdec59b8a93959d80e9ef88e0bfb692092db505c95a50fcd32735f4dda8e
data/.travis.yml CHANGED
@@ -1,6 +1,9 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 2.1.2
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
4
7
  gemfile:
5
8
  - Gemfile.rails-4.2
6
9
  - Gemfile.rails-4.1
@@ -8,6 +11,8 @@ gemfile:
8
11
  - Gemfile.rails-3.2
9
12
  - Gemfile.rails-3.1
10
13
  - Gemfile.rails-3.0
14
+ - Gemfile.mongoid-5.0
15
+ - Gemfile.mongoid-4.0
11
16
  - Gemfile.mongoid-3.1
12
17
  - Gemfile.mongoid-3.0
13
18
  - Gemfile.mongoid-2.8
@@ -19,3 +24,25 @@ env:
19
24
  - DB=sqlite
20
25
  services:
21
26
  - mongodb
27
+ matrix:
28
+ exclude:
29
+ - rvm: 2.2
30
+ gemfile: Gemfile.rails-3.0
31
+ - rvm: 2.2
32
+ gemfile: Gemfile.rails-3.1
33
+ - rvm: 2.2
34
+ gemfile: Gemfile.rails-3.2
35
+ - rvm: 2.2
36
+ gemfile: Gemfile.mongoid-3.1
37
+ - rvm: 2.2
38
+ gemfile: Gemfile.mongoid-3.0
39
+ - rvm: 2.2
40
+ gemfile: Gemfile.mongoid-2.8
41
+ - rvm: 2.2
42
+ gemfile: Gemfile.mongoid-2.7
43
+ - rvm: 2.2
44
+ gemfile: Gemfile.mongoid-2.6
45
+ - rvm: 2.2
46
+ gemfile: Gemfile.mongoid-2.5
47
+ - rvm: 2.2
48
+ gemfile: Gemfile.mongoid-2.4
data/CHANGELOG.md CHANGED
@@ -1,16 +1,52 @@
1
1
  # Next Release
2
2
 
3
+ ## 4.14.10
4
+
5
+ * Fix `has_many :through` infinite loop issue
6
+
7
+ ## 4.14.9
8
+
9
+ * Support mongoid 5.0.0
10
+ * Do not report association queries immediately after object creation to
11
+ require a preload
12
+ * Detect `counter_cache` for `has_many :through` association
13
+
14
+ ## 4.14.8
15
+
16
+ * compatible with `composite_primary_keys` gem
17
+
18
+ ## 4.14.7
19
+
20
+ * Fix AR 4.2 SingularAssociation#reader result can be nil
21
+ * `perform_out_of_channel_notifications` should always be triggered
22
+
23
+ ## 4.14.6
24
+
25
+ * Fix false positive with `belongs_to` -> `belongs_to` for active\_record 4.2
26
+ * Activate active\_record hacks only when Bullet already start
27
+
28
+ ## 4.14.5
29
+
30
+ * Don't execute query when running `to_sql`
31
+ * Send backtrace to `uniform_notifier`
32
+ * Fix sse response check
33
+ * Dynamically delegate available notifiers to UniformNotifier
34
+
35
+ ## 4.14.4
36
+
37
+ * Fix false N + 1 warnings on Rails 4.2
38
+
3
39
  ## 4.14.3
4
40
 
5
41
  * Fix false positive on create
6
42
 
7
43
  ## 4.14.2
8
44
 
9
- * Hotfix nil object when add_impossible_object
45
+ * Hotfix nil object when `add_impossible_object`
10
46
 
11
47
  ## 4.14.1
12
48
 
13
- * Fix has_one then has_many associations in rails 4.2
49
+ * Fix `has_one` then `has_many` associations in rails 4.2
14
50
  * Append js and dom to html body in proper position
15
51
 
16
52
  ## 4.14.0 (10/03/2014)
data/Gemfile.mongoid CHANGED
@@ -8,7 +8,5 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'mongoid', github: 'mongoid/mongoid'
9
9
 
10
10
  gem "rspec"
11
- gem "guard"
12
- gem "guard-rspec"
13
11
 
14
12
  gem 'coveralls', require: false
data/Gemfile.mongoid-2.4 CHANGED
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
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
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
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
@@ -8,8 +8,6 @@ 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
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
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
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
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
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
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
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
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
@@ -8,8 +8,6 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
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
 
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 4.0.0'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mongoid', '~> 5.0.0.beta', github: 'mongoid'
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/Gemfile.rails-3.1 CHANGED
@@ -8,8 +8,6 @@ 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
@@ -8,8 +8,6 @@ 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
@@ -8,8 +8,6 @@ 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
@@ -8,8 +8,6 @@ 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 CHANGED
@@ -8,8 +8,6 @@ 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/README.md CHANGED
@@ -36,6 +36,9 @@ or add it into a Gemfile (Bundler):
36
36
  gem "bullet", :group => "development"
37
37
  ```
38
38
 
39
+ **Note**: make sure `bullet` gem is added after activerecord (rails) and
40
+ mongoid.
41
+
39
42
  ## Configuration
40
43
 
41
44
  Bullet won't do ANYTHING unless you tell it to explicitly. Append to
@@ -53,10 +56,13 @@ config.after_initialize do
53
56
  :receiver => 'your_account@jabber.org',
54
57
  :show_online_status => true }
55
58
  Bullet.rails_logger = true
59
+ Bullet.honeybadger = true
56
60
  Bullet.bugsnag = true
57
61
  Bullet.airbrake = true
62
+ Bullet.rollbar = true
58
63
  Bullet.add_footer = true
59
64
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
65
+ Bullet.slack = { webhook_url: 'http://some.slack.url', foo: 'bar' }
60
66
  end
61
67
  ```
62
68
 
@@ -67,14 +73,17 @@ The code above will enable all seven of the Bullet notification systems:
67
73
  * `Bullet.alert`: pop up a JavaScript alert in the browser
68
74
  * `Bullet.bullet_logger`: log to the Bullet log file (Rails.root/log/bullet.log)
69
75
  * `Bullet.rails_logger`: add warnings directly to the Rails log
76
+ * `Bullet.honeybadger`: add notifications to Honeybadger
70
77
  * `Bullet.bugsnag`: add notifications to bugsnag
71
78
  * `Bullet.airbrake`: add notifications to airbrake
79
+ * `Bullet.rollbar`: add notifications to rollbar
72
80
  * `Bullet.console`: log warnings to your browser's console.log (Safari/Webkit browsers or Firefox w/Firebug installed)
73
81
  * `Bullet.growl`: pop up Growl warnings if your system has Growl installed. Requires a little bit of configuration
74
82
  * `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.
75
83
  * `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
76
84
  * `Bullet.add_footer`: adds the details in the bottom left corner of the page
77
85
  * `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
86
+ * `Bullet.slack`: add notifications to slack
78
87
 
79
88
  Bullet also allows you to disable any of its detectors.
80
89
 
@@ -103,6 +112,22 @@ Bullet.add_whitelist :type => :unused_eager_loading, :class_name => "Post", :ass
103
112
  Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities
104
113
  ```
105
114
 
115
+ If you want to skip bullet in some specific controller actions, you can
116
+ do like
117
+
118
+ ```ruby
119
+ class ApplicationController < ActionController::Base
120
+ around_action :skip_bullet
121
+
122
+ def skip_bullet
123
+ Bullet.enable = false
124
+ yield
125
+ ensure
126
+ Bullet.enable = true
127
+ end
128
+ end
129
+ ```
130
+
106
131
  ## Log
107
132
 
108
133
  The Bullet log `log/bullet.log` will look something like this:
@@ -154,8 +179,9 @@ The Bullet gem uses rack middleware to profile requests. If you want to use Bull
154
179
  ```ruby
155
180
  Bullet.profile do
156
181
  # do anything
182
+
183
+ warnings = Bullet.warnings
157
184
  end
158
- warnings = Bullet.warnings
159
185
  ```
160
186
 
161
187
  ### Work with sinatra
data/bullet.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.required_rubygems_version = ">= 1.3.6"
19
19
 
20
20
  s.add_runtime_dependency "activesupport", ">= 3.0.0"
21
- s.add_runtime_dependency "uniform_notifier", ">= 1.6.0"
21
+ s.add_runtime_dependency "uniform_notifier", "~> 1.9.0"
22
22
 
23
23
  s.files = `git ls-files`.split("\n")
24
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,5 +1,7 @@
1
1
  module Bullet
2
2
  module ActiveRecord
3
+ LOAD_TARGET = 'load_target'.freeze
4
+
3
5
  def self.enable
4
6
  require 'active_record'
5
7
  ::ActiveRecord::Relation.class_eval do
@@ -8,12 +10,14 @@ module Bullet
8
10
  # if select only one object, then the only one object has impossible to cause N+1 query.
9
11
  def to_a
10
12
  records = origin_to_a
11
- if records.size > 1
12
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
13
- Bullet::Detector::CounterCache.add_possible_objects(records)
14
- elsif records.size == 1
15
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
16
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
13
+ if Bullet.start?
14
+ if records.size > 1
15
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
16
+ Bullet::Detector::CounterCache.add_possible_objects(records)
17
+ elsif records.size == 1
18
+ Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
19
+ Bullet::Detector::CounterCache.add_impossible_object(records.first)
20
+ end
17
21
  end
18
22
  records
19
23
  end
@@ -24,12 +28,14 @@ module Bullet
24
28
  # include query for one to many associations.
25
29
  # keep this eager loadings.
26
30
  def preload_associations(records, associations, preload_options={})
27
- records = [records].flatten.compact.uniq
28
- return if records.empty?
29
- records.each do |record|
30
- Bullet::Detector::Association.add_object_associations(record, associations)
31
+ if Bullet.start?
32
+ records = [records].flatten.compact.uniq
33
+ return if records.empty?
34
+ records.each do |record|
35
+ Bullet::Detector::Association.add_object_associations(record, associations)
36
+ end
37
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
31
38
  end
32
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
33
39
  origin_preload_associations(records, associations, preload_options={})
34
40
  end
35
41
  end
@@ -39,11 +45,13 @@ module Bullet
39
45
  alias_method :origin_find_with_associations, :find_with_associations
40
46
  def find_with_associations
41
47
  records = origin_find_with_associations
42
- associations = (@eager_load_values + @includes_values).uniq
43
- records.each do |record|
44
- Bullet::Detector::Association.add_object_associations(record, associations)
48
+ if Bullet.start?
49
+ associations = (@eager_load_values + @includes_values).uniq
50
+ records.each do |record|
51
+ Bullet::Detector::Association.add_object_associations(record, associations)
52
+ end
53
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
45
54
  end
46
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
47
55
  records
48
56
  end
49
57
  end
@@ -56,9 +64,11 @@ module Bullet
56
64
  @bullet_eager_loadings = {}
57
65
  records = origin_instantiate(rows)
58
66
 
59
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
60
- objects = eager_loadings_hash.keys
61
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
67
+ if Bullet.start?
68
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
69
+ objects = eager_loadings_hash.keys
70
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
71
+ end
62
72
  end
63
73
  records
64
74
  end
@@ -67,12 +77,14 @@ module Bullet
67
77
  def construct_association(record, join, row)
68
78
  result = origin_construct_association(record, join, row)
69
79
 
70
- associations = join.reflection.name
71
- Bullet::Detector::Association.add_object_associations(record, associations)
72
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
73
- @bullet_eager_loadings[record.class] ||= {}
74
- @bullet_eager_loadings[record.class][record] ||= Set.new
75
- @bullet_eager_loadings[record.class][record] << associations
80
+ if Bullet.start?
81
+ associations = join.reflection.name
82
+ Bullet::Detector::Association.add_object_associations(record, associations)
83
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
84
+ @bullet_eager_loadings[record.class] ||= {}
85
+ @bullet_eager_loadings[record.class][record] ||= Set.new
86
+ @bullet_eager_loadings[record.class][record] << associations
87
+ end
76
88
 
77
89
  result
78
90
  end
@@ -82,31 +94,41 @@ module Bullet
82
94
  # call one to many associations
83
95
  alias_method :origin_load_target, :load_target
84
96
  def load_target
85
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
97
+ if Bullet.start?
98
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
99
+ end
86
100
  origin_load_target
87
101
  end
88
102
 
89
103
  alias_method :origin_first, :first
90
104
  def first(*args)
91
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
105
+ if Bullet.start?
106
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
107
+ end
92
108
  origin_first(*args)
93
109
  end
94
110
 
95
111
  alias_method :origin_last, :last
96
112
  def last(*args)
97
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
113
+ if Bullet.start?
114
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
115
+ end
98
116
  origin_last(*args)
99
117
  end
100
118
 
101
119
  alias_method :origin_empty?, :empty?
102
120
  def empty?
103
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
121
+ if Bullet.start?
122
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
123
+ end
104
124
  origin_empty?
105
125
  end
106
126
 
107
127
  alias_method :origin_include?, :include?
108
128
  def include?(object)
109
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
129
+ if Bullet.start?
130
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
131
+ end
110
132
  origin_include?(object)
111
133
  end
112
134
  end
@@ -117,15 +139,19 @@ module Bullet
117
139
  def load_target
118
140
  # avoid stack level too deep
119
141
  result = origin_load_target
120
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?("load_target") }
121
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
142
+ if Bullet.start?
143
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?(LOAD_TARGET) }
144
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
145
+ end
122
146
  result
123
147
  end
124
148
 
125
149
  alias_method :origin_set_inverse_instance, :set_inverse_instance
126
150
  def set_inverse_instance(record, instance)
127
- if record && we_can_set_the_inverse_on_this?(record)
128
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
151
+ if Bullet.start?
152
+ if record && we_can_set_the_inverse_on_this?(record)
153
+ Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
154
+ end
129
155
  end
130
156
  origin_set_inverse_instance(record, instance)
131
157
  end
@@ -136,7 +162,9 @@ module Bullet
136
162
 
137
163
  def has_cached_counter?
138
164
  result = origin_has_cached_counter?
139
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
165
+ if Bullet.start? && !result
166
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
167
+ end
140
168
  result
141
169
  end
142
170
  end
@@ -145,7 +173,9 @@ module Bullet
145
173
  alias_method :origin_has_cached_counter?, :has_cached_counter?
146
174
  def has_cached_counter?
147
175
  result = origin_has_cached_counter?
148
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
176
+ if Bullet.start? && !result
177
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
178
+ end
149
179
  result
150
180
  end
151
181
  end