bullet 4.14.5 → 4.14.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a56f8b0100130149fc7c45ceb660b4b100b84b8
4
- data.tar.gz: 44a4a67d0ab54bbc6ab8cfef656257e40131e7ab
3
+ metadata.gz: 6f638b646b9513031fb22f2e225286902ca056d5
4
+ data.tar.gz: f9144079dd390c7f7c3bb5f584b9b7f5c9552ec7
5
5
  SHA512:
6
- metadata.gz: bdb47a4a12f599a6c35113a13ba9ed3559c220e06731beb2ff86d4bec9de0a019425c47d3b19c22e987d7106a930a15c985c56f057edd521a6a5000a76c126d8
7
- data.tar.gz: 872c82a3e4d7ce373064c7738a45a012e1a001c35b428c49380635723d119bb3828a48e336eed733cdd2bf48905f6ad627dc6061a20b51ebf0b294aa093ca3a4
6
+ metadata.gz: 646ba3c219617f31c8e0b2e0f31b106c9a6a17db3029241e1b0bd53341532d9982e4c8e01ffbba5094423edf337e86e56b45b923b9000ba151fd5370bcfbc8b7
7
+ data.tar.gz: 9a75eb39b6bd37f8f14d343e90aea52ac7438771755374799f423890f7181454c3cc10c0bd0502c577be62e38ad2193867934a4fd36837d411ffe40077de562e
@@ -1,5 +1,10 @@
1
1
  # Next Release
2
2
 
3
+ ## 4.14.6
4
+
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
+
3
8
  ## 4.14.5
4
9
 
5
10
  * Don't execute query when running `to_sql`
data/README.md CHANGED
@@ -53,6 +53,7 @@ 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
58
59
  Bullet.rollbar = true
@@ -69,6 +70,7 @@ The code above will enable all seven of the Bullet notification systems:
69
70
  * `Bullet.alert`: pop up a JavaScript alert in the browser
70
71
  * `Bullet.bullet_logger`: log to the Bullet log file (Rails.root/log/bullet.log)
71
72
  * `Bullet.rails_logger`: add warnings directly to the Rails log
73
+ * `Bullet.honeybadger`: add notifications to Honeybadger
72
74
  * `Bullet.bugsnag`: add notifications to bugsnag
73
75
  * `Bullet.airbrake`: add notifications to airbrake
74
76
  * `Bullet.rollbar`: add notifications to rollbar
@@ -29,7 +29,9 @@ module Bullet
29
29
  attr_reader :notification_collector, :whitelist
30
30
  attr_accessor :add_footer, :orm_pathches_applied
31
31
 
32
- delegate *UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }, :to => UniformNotifier
32
+ available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
33
+ available_notifiers << { :to => UniformNotifier }
34
+ delegate *available_notifiers
33
35
 
34
36
  def raise=(should_raise)
35
37
  UniformNotifier.raise=(should_raise ? Notification::UnoptimizedQueryError : false)
@@ -8,12 +8,14 @@ module Bullet
8
8
  # if select only one object, then the only one object has impossible to cause N+1 query.
9
9
  def to_a
10
10
  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)
11
+ if Bullet.start?
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
17
19
  end
18
20
  records
19
21
  end
@@ -24,12 +26,14 @@ module Bullet
24
26
  # include query for one to many associations.
25
27
  # keep this eager loadings.
26
28
  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)
29
+ if Bullet.start?
30
+ records = [records].flatten.compact.uniq
31
+ return if records.empty?
32
+ records.each do |record|
33
+ Bullet::Detector::Association.add_object_associations(record, associations)
34
+ end
35
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
31
36
  end
32
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
33
37
  origin_preload_associations(records, associations, preload_options={})
34
38
  end
35
39
  end
@@ -39,11 +43,13 @@ module Bullet
39
43
  alias_method :origin_find_with_associations, :find_with_associations
40
44
  def find_with_associations
41
45
  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)
46
+ if Bullet.start?
47
+ associations = (@eager_load_values + @includes_values).uniq
48
+ records.each do |record|
49
+ Bullet::Detector::Association.add_object_associations(record, associations)
50
+ end
51
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
45
52
  end
46
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
47
53
  records
48
54
  end
49
55
  end
@@ -56,9 +62,11 @@ module Bullet
56
62
  @bullet_eager_loadings = {}
57
63
  records = origin_instantiate(rows)
58
64
 
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)
65
+ if Bullet.start?
66
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
67
+ objects = eager_loadings_hash.keys
68
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
69
+ end
62
70
  end
63
71
  records
64
72
  end
@@ -67,12 +75,14 @@ module Bullet
67
75
  def construct_association(record, join, row)
68
76
  result = origin_construct_association(record, join, row)
69
77
 
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
78
+ if Bullet.start?
79
+ associations = join.reflection.name
80
+ Bullet::Detector::Association.add_object_associations(record, associations)
81
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
82
+ @bullet_eager_loadings[record.class] ||= {}
83
+ @bullet_eager_loadings[record.class][record] ||= Set.new
84
+ @bullet_eager_loadings[record.class][record] << associations
85
+ end
76
86
 
77
87
  result
78
88
  end
@@ -82,31 +92,41 @@ module Bullet
82
92
  # call one to many associations
83
93
  alias_method :origin_load_target, :load_target
84
94
  def load_target
85
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
95
+ if Bullet.start?
96
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
97
+ end
86
98
  origin_load_target
87
99
  end
88
100
 
89
101
  alias_method :origin_first, :first
90
102
  def first(*args)
91
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
103
+ if Bullet.start?
104
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
105
+ end
92
106
  origin_first(*args)
93
107
  end
94
108
 
95
109
  alias_method :origin_last, :last
96
110
  def last(*args)
97
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
111
+ if Bullet.start?
112
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
113
+ end
98
114
  origin_last(*args)
99
115
  end
100
116
 
101
117
  alias_method :origin_empty?, :empty?
102
118
  def empty?
103
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
119
+ if Bullet.start?
120
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
121
+ end
104
122
  origin_empty?
105
123
  end
106
124
 
107
125
  alias_method :origin_include?, :include?
108
126
  def include?(object)
109
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
127
+ if Bullet.start?
128
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
129
+ end
110
130
  origin_include?(object)
111
131
  end
112
132
  end
@@ -117,15 +137,19 @@ module Bullet
117
137
  def load_target
118
138
  # avoid stack level too deep
119
139
  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)
140
+ if Bullet.start?
141
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?("load_target") }
142
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
143
+ end
122
144
  result
123
145
  end
124
146
 
125
147
  alias_method :origin_set_inverse_instance, :set_inverse_instance
126
148
  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)
149
+ if Bullet.start?
150
+ if record && we_can_set_the_inverse_on_this?(record)
151
+ Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
152
+ end
129
153
  end
130
154
  origin_set_inverse_instance(record, instance)
131
155
  end
@@ -136,7 +160,9 @@ module Bullet
136
160
 
137
161
  def has_cached_counter?
138
162
  result = origin_has_cached_counter?
139
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
163
+ if Bullet.start?
164
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
165
+ end
140
166
  result
141
167
  end
142
168
  end
@@ -145,7 +171,9 @@ module Bullet
145
171
  alias_method :origin_has_cached_counter?, :has_cached_counter?
146
172
  def has_cached_counter?
147
173
  result = origin_has_cached_counter?
148
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
174
+ if Bullet.start?
175
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
176
+ end
149
177
  result
150
178
  end
151
179
  end
@@ -8,12 +8,14 @@ module Bullet
8
8
  # if select only one object, then the only one object has impossible to cause N+1 query.
9
9
  def to_a
10
10
  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)
11
+ if Bullet.start?
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
17
19
  end
18
20
  records
19
21
  end
@@ -25,12 +27,14 @@ module Bullet
25
27
  alias_method :origin_initialize, :initialize
26
28
  def initialize(records, associations, preload_scope = nil)
27
29
  origin_initialize(records, associations, preload_scope)
28
- records = [records].flatten.compact.uniq
29
- return if records.empty?
30
- records.each do |record|
31
- Bullet::Detector::Association.add_object_associations(record, associations)
30
+ if Bullet.start?
31
+ records = [records].flatten.compact.uniq
32
+ return if records.empty?
33
+ records.each do |record|
34
+ Bullet::Detector::Association.add_object_associations(record, associations)
35
+ end
36
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
32
37
  end
33
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
34
38
  end
35
39
  end
36
40
 
@@ -39,11 +43,13 @@ module Bullet
39
43
  alias_method :origin_find_with_associations, :find_with_associations
40
44
  def find_with_associations
41
45
  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)
46
+ if Bullet.start?
47
+ associations = (eager_load_values + includes_values).uniq
48
+ records.each do |record|
49
+ Bullet::Detector::Association.add_object_associations(record, associations)
50
+ end
51
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
45
52
  end
46
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
47
53
  records
48
54
  end
49
55
  end
@@ -56,9 +62,11 @@ module Bullet
56
62
  @bullet_eager_loadings = {}
57
63
  records = origin_instantiate(rows)
58
64
 
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)
65
+ if Bullet.start?
66
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
67
+ objects = eager_loadings_hash.keys
68
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
69
+ end
62
70
  end
63
71
  records
64
72
  end
@@ -67,12 +75,14 @@ module Bullet
67
75
  def construct_association(record, join, row)
68
76
  result = origin_construct_association(record, join, row)
69
77
 
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
78
+ if Bullet.start?
79
+ associations = join.reflection.name
80
+ Bullet::Detector::Association.add_object_associations(record, associations)
81
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
82
+ @bullet_eager_loadings[record.class] ||= {}
83
+ @bullet_eager_loadings[record.class][record] ||= Set.new
84
+ @bullet_eager_loadings[record.class][record] << associations
85
+ end
76
86
 
77
87
  result
78
88
  end
@@ -82,19 +92,25 @@ module Bullet
82
92
  # call one to many associations
83
93
  alias_method :origin_load_target, :load_target
84
94
  def load_target
85
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
95
+ if Bullet.start?
96
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
97
+ end
86
98
  origin_load_target
87
99
  end
88
100
 
89
101
  alias_method :origin_empty?, :empty?
90
102
  def empty?
91
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
103
+ if Bullet.start?
104
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
105
+ end
92
106
  origin_empty?
93
107
  end
94
108
 
95
109
  alias_method :origin_include?, :include?
96
110
  def include?(object)
97
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
111
+ if Bullet.start?
112
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
113
+ end
98
114
  origin_include?(object)
99
115
  end
100
116
  end
@@ -104,8 +120,10 @@ module Bullet
104
120
  alias_method :origin_reader, :reader
105
121
  def reader(force_reload = false)
106
122
  result = origin_reader(force_reload)
107
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
108
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
123
+ if Bullet.start?
124
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
125
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
126
+ end
109
127
  result
110
128
  end
111
129
  end
@@ -113,8 +131,10 @@ module Bullet
113
131
  ::ActiveRecord::Associations::Association.class_eval do
114
132
  alias_method :origin_set_inverse_instance, :set_inverse_instance
115
133
  def set_inverse_instance(record)
116
- if record && invertible_for?(record)
117
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, inverse_reflection_for(record).name)
134
+ if Bullet.start?
135
+ if record && invertible_for?(record)
136
+ Bullet::Detector::NPlusOneQuery.add_inversed_object(record, inverse_reflection_for(record).name)
137
+ end
118
138
  end
119
139
  origin_set_inverse_instance(record)
120
140
  end
@@ -123,9 +143,11 @@ module Bullet
123
143
  ::ActiveRecord::Associations::HasManyAssociation.class_eval do
124
144
  alias_method :origin_has_cached_counter?, :has_cached_counter?
125
145
 
126
- def has_cached_counter?(reflection = reflection())
146
+ def has_cached_counter?(reflection = reflection)
127
147
  result = origin_has_cached_counter?(reflection)
128
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
148
+ if Bullet.start?
149
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
150
+ end
129
151
  result
130
152
  end
131
153
  end
@@ -8,12 +8,14 @@ module Bullet
8
8
  # if select only one object, then the only one object has impossible to cause N+1 query.
9
9
  def to_a
10
10
  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)
11
+ if Bullet.start?
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
17
19
  end
18
20
  records
19
21
  end
@@ -25,12 +27,14 @@ module Bullet
25
27
  alias_method :origin_initialize, :initialize
26
28
  def initialize(records, associations, preload_scope = nil)
27
29
  origin_initialize(records, associations, preload_scope)
28
- records = [records].flatten.compact.uniq
29
- return if records.empty?
30
- records.each do |record|
31
- Bullet::Detector::Association.add_object_associations(record, associations)
30
+ if Bullet.start?
31
+ records = [records].flatten.compact.uniq
32
+ return if records.empty?
33
+ records.each do |record|
34
+ Bullet::Detector::Association.add_object_associations(record, associations)
35
+ end
36
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
32
37
  end
33
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
34
38
  end
35
39
  end
36
40
 
@@ -39,11 +43,13 @@ module Bullet
39
43
  alias_method :origin_find_with_associations, :find_with_associations
40
44
  def find_with_associations
41
45
  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)
46
+ if Bullet.start?
47
+ associations = (eager_load_values + includes_values).uniq
48
+ records.each do |record|
49
+ Bullet::Detector::Association.add_object_associations(record, associations)
50
+ end
51
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
45
52
  end
46
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
47
53
  records
48
54
  end
49
55
  end
@@ -56,9 +62,11 @@ module Bullet
56
62
  @bullet_eager_loadings = {}
57
63
  records = origin_instantiate(rows)
58
64
 
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)
65
+ if Bullet.start?
66
+ @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
67
+ objects = eager_loadings_hash.keys
68
+ Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
69
+ end
62
70
  end
63
71
  records
64
72
  end
@@ -67,12 +75,14 @@ module Bullet
67
75
  def construct_association(record, join, row)
68
76
  result = origin_construct_association(record, join, row)
69
77
 
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
78
+ if Bullet.start?
79
+ associations = join.reflection.name
80
+ Bullet::Detector::Association.add_object_associations(record, associations)
81
+ Bullet::Detector::NPlusOneQuery.call_association(record, associations)
82
+ @bullet_eager_loadings[record.class] ||= {}
83
+ @bullet_eager_loadings[record.class][record] ||= Set.new
84
+ @bullet_eager_loadings[record.class][record] << associations
85
+ end
76
86
 
77
87
  result
78
88
  end
@@ -82,19 +92,25 @@ module Bullet
82
92
  # call one to many associations
83
93
  alias_method :origin_load_target, :load_target
84
94
  def load_target
85
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
95
+ if Bullet.start?
96
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
97
+ end
86
98
  origin_load_target
87
99
  end
88
100
 
89
101
  alias_method :origin_empty?, :empty?
90
102
  def empty?
91
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
103
+ if Bullet.start?
104
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
105
+ end
92
106
  origin_empty?
93
107
  end
94
108
 
95
109
  alias_method :origin_include?, :include?
96
110
  def include?(object)
97
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
111
+ if Bullet.start?
112
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
113
+ end
98
114
  origin_include?(object)
99
115
  end
100
116
  end
@@ -104,9 +120,11 @@ module Bullet
104
120
  alias_method :origin_reader, :reader
105
121
  def reader(force_reload = false)
106
122
  result = origin_reader(force_reload)
107
- unless @inversed
108
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
109
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
123
+ if Bullet.start?
124
+ unless @inversed
125
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
126
+ Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
127
+ end
110
128
  end
111
129
  result
112
130
  end
@@ -117,7 +135,9 @@ module Bullet
117
135
 
118
136
  def has_cached_counter?(reflection = reflection())
119
137
  result = origin_has_cached_counter?(reflection)
120
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
138
+ if Bullet.start?
139
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
140
+ end
121
141
  result
122
142
  end
123
143
  end