bullet 6.0.0 → 6.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +20 -1
  3. data/CHANGELOG.md +26 -1
  4. data/Gemfile.rails-6.0 +1 -1
  5. data/Gemfile.rails-6.1 +15 -0
  6. data/README.md +30 -9
  7. data/lib/bullet.rb +26 -16
  8. data/lib/bullet/active_job.rb +13 -0
  9. data/lib/bullet/active_record4.rb +9 -24
  10. data/lib/bullet/active_record41.rb +7 -19
  11. data/lib/bullet/active_record42.rb +8 -16
  12. data/lib/bullet/active_record5.rb +188 -170
  13. data/lib/bullet/active_record52.rb +176 -161
  14. data/lib/bullet/active_record60.rb +193 -171
  15. data/lib/bullet/active_record61.rb +267 -0
  16. data/lib/bullet/bullet_xhr.js +32 -27
  17. data/lib/bullet/dependency.rb +42 -34
  18. data/lib/bullet/detector/association.rb +24 -18
  19. data/lib/bullet/detector/base.rb +1 -2
  20. data/lib/bullet/detector/counter_cache.rb +10 -6
  21. data/lib/bullet/detector/n_plus_one_query.rb +18 -8
  22. data/lib/bullet/detector/unused_eager_loading.rb +5 -2
  23. data/lib/bullet/mongoid4x.rb +2 -6
  24. data/lib/bullet/mongoid5x.rb +2 -6
  25. data/lib/bullet/mongoid6x.rb +2 -6
  26. data/lib/bullet/mongoid7x.rb +2 -6
  27. data/lib/bullet/notification/base.rb +14 -18
  28. data/lib/bullet/notification/n_plus_one_query.rb +2 -4
  29. data/lib/bullet/notification/unused_eager_loading.rb +2 -4
  30. data/lib/bullet/rack.rb +21 -13
  31. data/lib/bullet/stack_trace_filter.rb +5 -10
  32. data/lib/bullet/version.rb +1 -1
  33. data/lib/generators/bullet/install_generator.rb +23 -23
  34. data/perf/benchmark.rb +8 -14
  35. data/spec/bullet/detector/counter_cache_spec.rb +6 -6
  36. data/spec/bullet/detector/n_plus_one_query_spec.rb +7 -3
  37. data/spec/bullet/detector/unused_eager_loading_spec.rb +19 -6
  38. data/spec/bullet/notification/base_spec.rb +1 -3
  39. data/spec/bullet/notification/n_plus_one_query_spec.rb +16 -3
  40. data/spec/bullet/notification/unused_eager_loading_spec.rb +5 -1
  41. data/spec/bullet/rack_spec.rb +76 -5
  42. data/spec/bullet/registry/association_spec.rb +2 -2
  43. data/spec/bullet/registry/base_spec.rb +1 -1
  44. data/spec/bullet_spec.rb +10 -29
  45. data/spec/integration/active_record/association_spec.rb +41 -122
  46. data/spec/integration/counter_cache_spec.rb +10 -30
  47. data/spec/integration/mongoid/association_spec.rb +18 -32
  48. data/spec/models/folder.rb +1 -2
  49. data/spec/models/group.rb +1 -2
  50. data/spec/models/page.rb +1 -2
  51. data/spec/models/writer.rb +1 -2
  52. data/spec/spec_helper.rb +6 -10
  53. data/spec/support/bullet_ext.rb +8 -9
  54. data/spec/support/mongo_seed.rb +2 -16
  55. metadata +9 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 749d1d92dc0373b1f2521c85825dfea656e985c438cdfafe774242b31f25c2d5
4
- data.tar.gz: 4e76a9da65613f2b9cf3802f4969f84c1e5bb9849c5892898fa9d999fde3900c
3
+ metadata.gz: 0363cc75d4facd4a8b4a318312a421040d5b21d7ca81c0b3af21daaf7c2b60cd
4
+ data.tar.gz: ac0b0e4ed9c1641b5359b3d885ef854934b85b8ee21bc0486a4c3d2661e20853
5
5
  SHA512:
6
- metadata.gz: 72f8f18edecb79d8631a215229afb71bb94050c0fcc65794a88dc3adf21545acf4ae38eb59bd6bdfa0e34609854ab149d02f47e761fba00452e28f2575306376
7
- data.tar.gz: 94058fcb502d63ce470b6dfa06d05dd367c8a7e251948040b91c22164d6583d8a82ab120bb2a42d109c121170042573c9964aaa55ebc0093c07adc1fb8f23fd5
6
+ metadata.gz: 199558c8186455fb2ddac94461d611d1c40eb0fb83ac68e36647efe0a34927020967a803cb24645b7ae3d5d045aa0060c604b455476f8c6aad6b5329103a7ebe
7
+ data.tar.gz: 86c4bcf9fcca52275229b7fa5e02919c39318d91a60c7fe956d4cab07442cbacfc3d9df134af1ee38bc7f153eeb2cd256faff45815ad83acd296c1831d1fc9ee
@@ -1,7 +1,7 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.3.0
4
+ - 2.6.0
5
5
  gemfile:
6
6
  - Gemfile.rails-6.0
7
7
  - Gemfile.rails-5.2
@@ -10,5 +10,24 @@ gemfile:
10
10
  - Gemfile.rails-4.2
11
11
  - Gemfile.rails-4.1
12
12
  - Gemfile.rails-4.0
13
+ matrix:
14
+ exclude:
15
+ - rvm: 2.3.0
16
+ gemfile: Gemfile.rails-6.0
17
+ - rvm: 2.6.0
18
+ gemfile: Gemfile.rails-5.2
19
+ - rvm: 2.6.0
20
+ gemfile: Gemfile.rails-5.1
21
+ - rvm: 2.6.0
22
+ gemfile: Gemfile.rails-5.0
23
+ - rvm: 2.6.0
24
+ gemfile: Gemfile.rails-4.2
25
+ - rvm: 2.6.0
26
+ gemfile: Gemfile.rails-4.1
27
+ - rvm: 2.6.0
28
+ gemfile: Gemfile.rails-4.0
13
29
  env:
14
30
  - DB=sqlite
31
+ before_install:
32
+ - "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
33
+ - gem install bundler -v '< 2'
@@ -1,6 +1,31 @@
1
1
  ## Next Release
2
2
 
3
- ## 6.0.0 (02/22/2019)
3
+ ## 6.1.2 (12/12/2020)
4
+
5
+ * Revert "Make whitelist thread safe"
6
+
7
+ ## 6.1.1 (12/12/2020)
8
+
9
+ * Add support Rails 6.1
10
+ * Make whitelist thread safe
11
+
12
+ ## 6.1.0 (12/28/2019)
13
+
14
+ * Add skip_html_injection flag
15
+ * Remove writer hack in active_record6
16
+ * Use modern includes syntax in warnings
17
+ * Fix warning: The last argument is used as the keyword parameter
18
+
19
+ ## 6.0.2 (08/20/2019)
20
+
21
+ * Fully support Rails 6.0
22
+
23
+ ## 6.0.1 (06/26/2019)
24
+
25
+ * Add Bullet::ActiveJob
26
+ * Prevent "Maximum call stack exceeded" errors when used with Turbolinks
27
+
28
+ ## 6.0.0 (04/25/2019)
4
29
 
5
30
  * Add XHR support to Bullet
6
31
  * Support Rails 6.0
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '6.0.0.rc1'
5
+ gem 'rails', '~> 6.0.0'
6
6
  gem 'sqlite3'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 6.1.0'
6
+ gem 'sqlite3'
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'activerecord-import'
9
+
10
+ gem "rspec"
11
+
12
+ platforms :rbx do
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'rubinius-developer_tools'
15
+ end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Bullet
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/bullet.png)](http://badge.fury.io/rb/bullet)
4
- [![Build Status](https://secure.travis-ci.org/flyerhzm/bullet.png)](http://travis-ci.org/flyerhzm/bullet)
3
+ [![Gem Version](https://badge.fury.io/rb/bullet.svg)](http://badge.fury.io/rb/bullet)
4
+ [![Build Status](https://secure.travis-ci.org/flyerhzm/bullet.svg)](http://travis-ci.org/flyerhzm/bullet)
5
5
  [![AwesomeCode Status for flyerhzm/bullet](https://awesomecode.io/projects/6755235b-e2c1-459e-bf92-b8b13d0c0472/status)](https://awesomecode.io/repos/flyerhzm/bullet)
6
6
  [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
7
7
 
@@ -37,6 +37,13 @@ or add it into a Gemfile (Bundler):
37
37
  gem 'bullet', group: 'development'
38
38
  ```
39
39
 
40
+ enable the Bullet gem with generate command
41
+
42
+ ```ruby
43
+ bundle exec rails g bullet:install
44
+ ```
45
+ The generate command will auto generate the default configuration and may ask to include in the test environment as well. See below for custom configuration.
46
+
40
47
  **Note**: make sure `bullet` gem is added after activerecord (rails) and
41
48
  mongoid.
42
49
 
@@ -63,6 +70,7 @@ config.after_initialize do
63
70
  Bullet.airbrake = true
64
71
  Bullet.rollbar = true
65
72
  Bullet.add_footer = true
73
+ Bullet.skip_html_injection = false
66
74
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
67
75
  Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware', ['my_file.rb', 'my_method'], ['my_file.rb', 16..20] ]
68
76
  Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
@@ -85,6 +93,7 @@ The code above will enable all of the Bullet notification systems:
85
93
  * `Bullet.rollbar`: add notifications to rollbar
86
94
  * `Bullet.sentry`: add notifications to sentry
87
95
  * `Bullet.add_footer`: adds the details in the bottom left corner of the page. Double click the footer or use close button to hide footer.
96
+ * `Bullet.skip_html_injection`: prevents Bullet from injecting XHR into the returned HTML. This must be false for receiving alerts or console logging.
88
97
  * `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
89
98
  * `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
90
99
  Each item can be a string (match substring), a regex, or an array where the first item is a path to match, and the second
@@ -125,7 +134,7 @@ do like
125
134
 
126
135
  ```ruby
127
136
  class ApplicationController < ActionController::Base
128
- around_action :skip_bullet
137
+ around_action :skip_bullet, if: -> { defined?(Bullet) }
129
138
 
130
139
  def skip_bullet
131
140
  previous_value = Bullet.enable?
@@ -181,15 +190,27 @@ If you find Bullet does not work for you, *please disable your browser's cache*.
181
190
 
182
191
  ## Advanced
183
192
 
184
- ### Profile a job
193
+ ### Work with ActiveJob
185
194
 
186
- 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 the profile method and fetch warnings
195
+ Include `Bullet::ActiveJob` in your `ApplicationJob`.
187
196
 
188
197
  ```ruby
189
- Bullet.profile do
190
- # do anything
198
+ class ApplicationJob < ActiveJob::Base
199
+ include Bullet::ActiveJob if Rails.env.development?
200
+ end
201
+ ```
202
+
203
+ ### Work with other background job solution
204
+
205
+ Use the Bullet.profile method.
191
206
 
192
- warnings = Bullet.warnings
207
+ ```ruby
208
+ class ApplicationJob < ActiveJob::Base
209
+ around_perform do |_job, block|
210
+ Bullet.profile do
211
+ block.call
212
+ end
213
+ end
193
214
  end
194
215
  ```
195
216
 
@@ -458,4 +479,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
458
479
  Post => [:comments]
459
480
  ```
460
481
 
461
- Copyright (c) 2009 - 2016 Richard Huang (flyerhzm@gmail.com), released under the MIT license
482
+ Copyright (c) 2009 - 2019 Richard Huang (flyerhzm@gmail.com), released under the MIT license
@@ -14,6 +14,7 @@ module Bullet
14
14
  autoload :ActiveRecord, "bullet/#{active_record_version}" if active_record?
15
15
  autoload :Mongoid, "bullet/#{mongoid_version}" if mongoid?
16
16
  autoload :Rack, 'bullet/rack'
17
+ autoload :ActiveJob, 'bullet/active_job'
17
18
  autoload :Notification, 'bullet/notification'
18
19
  autoload :Detector, 'bullet/detector'
19
20
  autoload :Registry, 'bullet/registry'
@@ -22,7 +23,7 @@ module Bullet
22
23
  BULLET_DEBUG = 'BULLET_DEBUG'
23
24
  TRUE = 'true'
24
25
 
25
- if defined? Rails::Railtie
26
+ if defined?(Rails::Railtie)
26
27
  class BulletRailtie < Rails::Railtie
27
28
  initializer 'bullet.configure_rails_initialization' do |app|
28
29
  app.middleware.use Bullet::Rack
@@ -31,28 +32,36 @@ module Bullet
31
32
  end
32
33
 
33
34
  class << self
34
- attr_writer :n_plus_one_query_enable, :unused_eager_loading_enable, :counter_cache_enable, :stacktrace_includes, :stacktrace_excludes
35
+ attr_writer :n_plus_one_query_enable,
36
+ :unused_eager_loading_enable,
37
+ :counter_cache_enable,
38
+ :stacktrace_includes,
39
+ :stacktrace_excludes,
40
+ :skip_html_injection
35
41
  attr_reader :whitelist
36
- attr_accessor :add_footer, :orm_pathches_applied
42
+ attr_accessor :add_footer, :orm_patches_applied
37
43
 
38
44
  available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
39
- available_notifiers << { to: UniformNotifier }
40
- delegate(*available_notifiers)
45
+ available_notifiers_options = { to: UniformNotifier }
46
+ delegate(*available_notifiers, **available_notifiers_options)
41
47
 
42
48
  def raise=(should_raise)
43
49
  UniformNotifier.raise = (should_raise ? Notification::UnoptimizedQueryError : false)
44
50
  end
45
51
 
46
- DETECTORS = [Bullet::Detector::NPlusOneQuery,
47
- Bullet::Detector::UnusedEagerLoading,
48
- Bullet::Detector::CounterCache].freeze
52
+ DETECTORS = [
53
+ Bullet::Detector::NPlusOneQuery,
54
+ Bullet::Detector::UnusedEagerLoading,
55
+ Bullet::Detector::CounterCache
56
+ ].freeze
49
57
 
50
58
  def enable=(enable)
51
59
  @enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable
60
+
52
61
  if enable?
53
62
  reset_whitelist
54
- unless orm_pathches_applied
55
- self.orm_pathches_applied = true
63
+ unless orm_patches_applied
64
+ self.orm_patches_applied = true
56
65
  Bullet::Mongoid.enable if mongoid?
57
66
  Bullet::ActiveRecord.enable if active_record?
58
67
  end
@@ -173,9 +182,7 @@ module Bullet
173
182
 
174
183
  def gather_inline_notifications
175
184
  responses = []
176
- for_each_active_notifier_with_notification do |notification|
177
- responses << notification.notify_inline
178
- end
185
+ for_each_active_notifier_with_notification { |notification| responses << notification.notify_inline }
179
186
  responses.join("\n")
180
187
  end
181
188
 
@@ -189,9 +196,7 @@ module Bullet
189
196
 
190
197
  def footer_info
191
198
  info = []
192
- notification_collector.collection.each do |notification|
193
- info << notification.short_notice
194
- end
199
+ notification_collector.collection.each { |notification| info << notification.short_notice }
195
200
  info
196
201
  end
197
202
 
@@ -213,6 +218,7 @@ module Bullet
213
218
 
214
219
  def profile
215
220
  return_value = nil
221
+
216
222
  if Bullet.enable?
217
223
  begin
218
224
  Bullet.start_request
@@ -234,6 +240,10 @@ module Bullet
234
240
  UniformNotifier.active_notifiers.include?(UniformNotifier::JavascriptConsole)
235
241
  end
236
242
 
243
+ def inject_into_page?
244
+ !@skip_html_injection && (console_enabled? || add_footer)
245
+ end
246
+
237
247
  private
238
248
 
239
249
  def for_each_active_notifier_with_notification
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bullet
4
+ module ActiveJob
5
+ def self.included(base)
6
+ base.class_eval do
7
+ around_perform do |_job, block|
8
+ Bullet.profile { block.call }
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,7 +5,7 @@ module Bullet
5
5
  def self.enable
6
6
  require 'active_record'
7
7
  ::ActiveRecord::Base.class_eval do
8
- class <<self
8
+ class << self
9
9
  alias_method :origin_find_by_sql, :find_by_sql
10
10
  def find_by_sql(sql, binds = [])
11
11
  result = origin_find_by_sql(sql, binds)
@@ -49,9 +49,7 @@ module Bullet
49
49
 
50
50
  ::ActiveRecord::Persistence.class_eval do
51
51
  def _create_record_with_bullet(*args)
52
- _create_record_without_bullet(*args).tap do
53
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
54
- end
52
+ _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
55
53
  end
56
54
  alias_method_chain :_create_record, :bullet
57
55
  end
@@ -62,13 +60,12 @@ module Bullet
62
60
  alias_method :origin_initialize, :initialize
63
61
  def initialize(records, associations, preload_scope = nil)
64
62
  origin_initialize(records, associations, preload_scope)
63
+
65
64
  if Bullet.start?
66
65
  records = [records].flatten.compact.uniq
67
66
  return if records.empty?
68
67
 
69
- records.each do |record|
70
- Bullet::Detector::Association.add_object_associations(record, associations)
71
- end
68
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
72
69
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
73
70
  end
74
71
  end
@@ -81,9 +78,7 @@ module Bullet
81
78
  records = origin_find_with_associations
82
79
  if Bullet.start?
83
80
  associations = (eager_load_values + includes_values).uniq
84
- records.each do |record|
85
- Bullet::Detector::Association.add_object_associations(record, associations)
86
- end
81
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
87
82
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
88
83
  end
89
84
  records
@@ -128,17 +123,13 @@ module Bullet
128
123
  # call one to many associations
129
124
  alias_method :origin_load_target, :load_target
130
125
  def load_target
131
- if Bullet.start?
132
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
133
- end
126
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
134
127
  origin_load_target
135
128
  end
136
129
 
137
130
  alias_method :origin_include?, :include?
138
131
  def include?(object)
139
- if Bullet.start?
140
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
141
- end
132
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
142
133
  origin_include?(object)
143
134
  end
144
135
  end
@@ -156,9 +147,7 @@ module Bullet
156
147
  ::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
157
148
  alias_method :origin_empty?, :empty?
158
149
  def empty?
159
- if Bullet.start? && !loaded?
160
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
161
- end
150
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start? && !loaded?
162
151
  origin_empty?
163
152
  end
164
153
  end
@@ -181,15 +170,11 @@ module Bullet
181
170
  ::ActiveRecord::Associations::HasManyAssociation.class_eval do
182
171
  alias_method :origin_has_cached_counter?, :has_cached_counter?
183
172
 
184
- # rubocop:disable Style/MethodCallWithoutArgsParentheses
185
173
  def has_cached_counter?(reflection = reflection())
186
174
  result = origin_has_cached_counter?(reflection)
187
- if Bullet.start? && !result
188
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
189
- end
175
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) if Bullet.start? && !result
190
176
  result
191
177
  end
192
- # rubocop:enable Style/MethodCallWithoutArgsParentheses
193
178
  end
194
179
  end
195
180
  end
@@ -5,7 +5,7 @@ module Bullet
5
5
  def self.enable
6
6
  require 'active_record'
7
7
  ::ActiveRecord::Base.class_eval do
8
- class <<self
8
+ class << self
9
9
  alias_method :origin_find_by_sql, :find_by_sql
10
10
  def find_by_sql(sql, binds = [])
11
11
  result = origin_find_by_sql(sql, binds)
@@ -51,9 +51,7 @@ module Bullet
51
51
 
52
52
  ::ActiveRecord::Persistence.class_eval do
53
53
  def _create_record_with_bullet(*args)
54
- _create_record_without_bullet(*args).tap do
55
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
56
- end
54
+ _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
57
55
  end
58
56
  alias_method_chain :_create_record, :bullet
59
57
  end
@@ -65,9 +63,7 @@ module Bullet
65
63
  if Bullet.start?
66
64
  records.compact!
67
65
  if records.first.class.name !~ /^HABTM_/
68
- records.each do |record|
69
- Bullet::Detector::Association.add_object_associations(record, association)
70
- end
66
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, association) }
71
67
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
72
68
  end
73
69
  end
@@ -84,9 +80,7 @@ module Bullet
84
80
  records = origin_find_with_associations
85
81
  if Bullet.start?
86
82
  associations = (eager_load_values + includes_values).uniq
87
- records.each do |record|
88
- Bullet::Detector::Association.add_object_associations(record, associations)
89
- end
83
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
90
84
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
91
85
  end
92
86
  records
@@ -131,9 +125,7 @@ module Bullet
131
125
  # call one to many associations
132
126
  alias_method :origin_load_target, :load_target
133
127
  def load_target
134
- if Bullet.start?
135
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
136
- end
128
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start? && !@inversed
137
129
  origin_load_target
138
130
  end
139
131
 
@@ -147,9 +139,7 @@ module Bullet
147
139
 
148
140
  alias_method :origin_include?, :include?
149
141
  def include?(object)
150
- if Bullet.start?
151
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
152
- end
142
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
153
143
  origin_include?(object)
154
144
  end
155
145
  end
@@ -173,9 +163,7 @@ module Bullet
173
163
  alias_method :origin_count_records, :count_records
174
164
  def count_records
175
165
  result = has_cached_counter?
176
- if Bullet.start? && !result
177
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
178
- end
166
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) if Bullet.start? && !result
179
167
  origin_count_records
180
168
  end
181
169
  end