bullet 5.8.1 → 6.1.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.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +22 -1
  3. data/CHANGELOG.md +24 -1
  4. data/Gemfile.mongoid-7.0 +15 -0
  5. data/Gemfile.rails-4.0 +1 -1
  6. data/Gemfile.rails-4.1 +1 -1
  7. data/Gemfile.rails-4.2 +1 -1
  8. data/Gemfile.rails-5.0 +1 -1
  9. data/Gemfile.rails-5.1 +1 -1
  10. data/Gemfile.rails-5.2 +1 -1
  11. data/Gemfile.rails-6.0 +15 -0
  12. data/README.md +24 -10
  13. data/lib/bullet.rb +42 -17
  14. data/lib/bullet/active_job.rb +9 -0
  15. data/lib/bullet/active_record4.rb +9 -32
  16. data/lib/bullet/active_record41.rb +7 -27
  17. data/lib/bullet/active_record42.rb +8 -24
  18. data/lib/bullet/active_record5.rb +188 -179
  19. data/lib/bullet/active_record52.rb +176 -168
  20. data/lib/bullet/active_record60.rb +267 -0
  21. data/lib/bullet/bullet_xhr.js +63 -0
  22. data/lib/bullet/dependency.rb +48 -34
  23. data/lib/bullet/detector/association.rb +26 -20
  24. data/lib/bullet/detector/base.rb +1 -2
  25. data/lib/bullet/detector/counter_cache.rb +13 -9
  26. data/lib/bullet/detector/n_plus_one_query.rb +22 -12
  27. data/lib/bullet/detector/unused_eager_loading.rb +6 -3
  28. data/lib/bullet/ext/object.rb +4 -2
  29. data/lib/bullet/mongoid4x.rb +2 -6
  30. data/lib/bullet/mongoid5x.rb +2 -6
  31. data/lib/bullet/mongoid6x.rb +2 -6
  32. data/lib/bullet/mongoid7x.rb +57 -0
  33. data/lib/bullet/notification/base.rb +14 -18
  34. data/lib/bullet/notification/n_plus_one_query.rb +2 -4
  35. data/lib/bullet/notification/unused_eager_loading.rb +2 -4
  36. data/lib/bullet/rack.rb +39 -20
  37. data/lib/bullet/stack_trace_filter.rb +6 -12
  38. data/lib/bullet/version.rb +1 -1
  39. data/lib/generators/bullet/install_generator.rb +4 -2
  40. data/perf/benchmark.rb +8 -14
  41. data/spec/bullet/detector/counter_cache_spec.rb +5 -5
  42. data/spec/bullet/detector/n_plus_one_query_spec.rb +7 -3
  43. data/spec/bullet/detector/unused_eager_loading_spec.rb +29 -12
  44. data/spec/bullet/ext/object_spec.rb +9 -4
  45. data/spec/bullet/notification/base_spec.rb +1 -3
  46. data/spec/bullet/notification/n_plus_one_query_spec.rb +18 -3
  47. data/spec/bullet/notification/unused_eager_loading_spec.rb +5 -1
  48. data/spec/bullet/rack_spec.rb +30 -6
  49. data/spec/bullet/registry/association_spec.rb +2 -2
  50. data/spec/bullet/registry/base_spec.rb +1 -1
  51. data/spec/bullet_spec.rb +10 -29
  52. data/spec/integration/active_record/association_spec.rb +45 -136
  53. data/spec/integration/counter_cache_spec.rb +11 -31
  54. data/spec/integration/mongoid/association_spec.rb +18 -32
  55. data/spec/models/folder.rb +1 -2
  56. data/spec/models/group.rb +1 -2
  57. data/spec/models/page.rb +1 -2
  58. data/spec/models/writer.rb +1 -2
  59. data/spec/spec_helper.rb +6 -10
  60. data/spec/support/bullet_ext.rb +8 -9
  61. data/spec/support/mongo_seed.rb +2 -16
  62. data/test.sh +2 -0
  63. data/update.sh +1 -0
  64. metadata +9 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7ae0cc579f8e882c40e1e244ba991acc79bac497
4
- data.tar.gz: '0558ed3107fd121dbf1ced92c20ef49609b0cc8d'
2
+ SHA256:
3
+ metadata.gz: dd668fdfd675ea8437eee0242974d7cb1cfacc0479be4cc5f3f58ee7d05a6d63
4
+ data.tar.gz: 3d841fb8471fe18b66135fa087ee3d1874f412c114d09ba05ba150e2daaf9775
5
5
  SHA512:
6
- metadata.gz: '019773e310b70aac51bb012d173c4354a8224f4808dcedbd1d0d58180faec7dc2738b78e15e14fe8a632a60a89f8423aea0fb9875feac28ca36c756235612bee'
7
- data.tar.gz: fe9a9caf06ff5daea8090187c551b35b983ba7d136d37f579ecdccdfab7e11b26fc989ac58e8df5b672ae20ab4931abcac014e03fefd024bab135d04a6412b1a
6
+ metadata.gz: 714c614f2cf44f332f4f9996638c10dca565c92a2279316509256fefba2ca824fc9c71d2a3c3e4ca28edfc45849f76b61e521158e0051c365f5b8a81f41e9d8d
7
+ data.tar.gz: a3b1a7e58b6e5554a641aa4b8edf16dbb4983b2f7a072c5b7275ee04a7251e4d095fed37f82d2945ef759603c8aeaf8a394d9e7fcf9f70a723e6235ab5f3e646
@@ -1,12 +1,33 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.3.0
4
+ - 2.6.0
5
5
  gemfile:
6
+ - Gemfile.rails-6.0
7
+ - Gemfile.rails-5.2
6
8
  - Gemfile.rails-5.1
7
9
  - Gemfile.rails-5.0
8
10
  - Gemfile.rails-4.2
9
11
  - Gemfile.rails-4.1
10
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
11
29
  env:
12
30
  - DB=sqlite
31
+ before_install:
32
+ - "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
33
+ - gem install bundler -v '< 2'
@@ -1,8 +1,31 @@
1
1
  ## Next Release
2
2
 
3
- ## 5.8.1
3
+ ## 6.1.0 (12/28/2019)
4
+
5
+ * Add skip_html_injection flag
6
+ * Remove writer hack in active_record6
7
+ * Use modern includes syntax in warnings
8
+ * Fix warning: The last argument is used as the keyword parameter
9
+
10
+ ## 6.0.2 (08/20/2019)
11
+
12
+ * Fully support Rails 6.0
13
+
14
+ ## 6.0.1 (06/26/2019)
15
+
16
+ * Add Bullet::ActiveJob
17
+ * Prevent "Maximum call stack exceeded" errors when used with Turbolinks
18
+
19
+ ## 6.0.0 (04/25/2019)
20
+
21
+ * Add XHR support to Bullet
22
+ * Support Rails 6.0
23
+ * Handle case where ID is manually set on unpersisted record
24
+
25
+ ## 5.9.0 (11/11/2018)
4
26
 
5
27
  * Require Ruby 2.3+
28
+ * Support Mongo 7.x
6
29
 
7
30
  ## 5.8.0 (10/29/2018)
8
31
 
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.0'
6
+ gem 'sqlite3', platforms: [:ruby]
7
+ gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
+ gem 'mongoid', '~> 7.0.0'
9
+
10
+ gem "rspec"
11
+
12
+ platforms :rbx do
13
+ gem 'rubysl', '~> 2.0'
14
+ gem 'rubinius-developer_tools'
15
+ end
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.0.0'
6
- gem 'sqlite3', platforms: [:ruby]
6
+ gem 'sqlite3', '~> 1.3.6', platforms: [:ruby]
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.1.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.2.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
  gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 5.0.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 5.1.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 5.2.0'
6
- gem 'sqlite3'
6
+ gem 'sqlite3', '~> 1.3.6'
7
7
  gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
8
  gem 'activerecord-import'
9
9
 
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '6.0.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
 
@@ -63,6 +63,7 @@ config.after_initialize do
63
63
  Bullet.airbrake = true
64
64
  Bullet.rollbar = true
65
65
  Bullet.add_footer = true
66
+ Bullet.skip_html_injection = false
66
67
  Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
67
68
  Bullet.stacktrace_excludes = [ 'their_gem', 'their_middleware', ['my_file.rb', 'my_method'], ['my_file.rb', 16..20] ]
68
69
  Bullet.slack = { webhook_url: 'http://some.slack.url', channel: '#default', username: 'notifier' }
@@ -85,6 +86,7 @@ The code above will enable all of the Bullet notification systems:
85
86
  * `Bullet.rollbar`: add notifications to rollbar
86
87
  * `Bullet.sentry`: add notifications to sentry
87
88
  * `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.
89
+ * `Bullet.skip_html_injection`: prevents Bullet from injecting XHR into the returned HTML. This must be false for receiving alerts or console logging.
88
90
  * `Bullet.stacktrace_includes`: include paths with any of these substrings in the stack trace, even if they are not in your main app
89
91
  * `Bullet.stacktrace_excludes`: ignore paths with any of these substrings in the stack trace, even if they are not in your main app.
90
92
  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 +127,7 @@ do like
125
127
 
126
128
  ```ruby
127
129
  class ApplicationController < ActionController::Base
128
- around_action :skip_bullet
130
+ around_action :skip_bullet, if: -> { defined?(Bullet) }
129
131
 
130
132
  def skip_bullet
131
133
  previous_value = Bullet.enable?
@@ -181,15 +183,27 @@ If you find Bullet does not work for you, *please disable your browser's cache*.
181
183
 
182
184
  ## Advanced
183
185
 
184
- ### Profile a job
186
+ ### Work with ActiveJob
185
187
 
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
188
+ Include `Bullet::ActiveJob` in your `ApplicationJob`.
187
189
 
188
190
  ```ruby
189
- Bullet.profile do
190
- # do anything
191
+ class ApplicationJob < ActiveJob::Base
192
+ include Bullet::ActiveJob if Rails.env.development?
193
+ end
194
+ ```
195
+
196
+ ### Work with other background job solution
191
197
 
192
- warnings = Bullet.warnings
198
+ Use the Bullet.profile method.
199
+
200
+ ```ruby
201
+ class ApplicationJob < ActiveJob::Base
202
+ around_perform do |_job, block|
203
+ Bullet.profile do
204
+ block.call
205
+ end
206
+ end
193
207
  end
194
208
  ```
195
209
 
@@ -221,7 +235,7 @@ end
221
235
  Then wrap each test in Bullet api.
222
236
 
223
237
  ```ruby
224
- # spec/spec_helper.rb
238
+ # spec/rails_helper.rb
225
239
  if Bullet.enable?
226
240
  config.before(:each) do
227
241
  Bullet.start_request
@@ -458,4 +472,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
458
472
  Post => [:comments]
459
473
  ```
460
474
 
461
- Copyright (c) 2009 - 2016 Richard Huang (flyerhzm@gmail.com), released under the MIT license
475
+ 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
@@ -63,6 +72,10 @@ module Bullet
63
72
  !!@enable
64
73
  end
65
74
 
75
+ def app_root
76
+ (defined?(::Rails.root) ? Rails.root.to_s : Dir.pwd).to_s
77
+ end
78
+
66
79
  def n_plus_one_query_enable?
67
80
  enable? && !!@n_plus_one_query_enable
68
81
  end
@@ -111,9 +124,8 @@ module Bullet
111
124
  def bullet_logger=(active)
112
125
  if active
113
126
  require 'fileutils'
114
- root_path = (rails? ? Rails.root.to_s : Dir.pwd).to_s
115
- FileUtils.mkdir_p(root_path + '/log')
116
- bullet_log_file = File.open("#{root_path}/log/bullet.log", 'a+')
127
+ FileUtils.mkdir_p(app_root + '/log')
128
+ bullet_log_file = File.open("#{app_root}/log/bullet.log", 'a+')
117
129
  bullet_log_file.sync = true
118
130
  UniformNotifier.customized_logger = bullet_log_file
119
131
  end
@@ -170,9 +182,7 @@ module Bullet
170
182
 
171
183
  def gather_inline_notifications
172
184
  responses = []
173
- for_each_active_notifier_with_notification do |notification|
174
- responses << notification.notify_inline
175
- end
185
+ for_each_active_notifier_with_notification { |notification| responses << notification.notify_inline }
176
186
  responses.join("\n")
177
187
  end
178
188
 
@@ -185,9 +195,15 @@ module Bullet
185
195
  end
186
196
 
187
197
  def footer_info
198
+ info = []
199
+ notification_collector.collection.each { |notification| info << notification.short_notice }
200
+ info
201
+ end
202
+
203
+ def text_notifications
188
204
  info = []
189
205
  notification_collector.collection.each do |notification|
190
- info << notification.short_notice
206
+ info << notification.notification_data.values.compact.join("\n")
191
207
  end
192
208
  info
193
209
  end
@@ -202,6 +218,7 @@ module Bullet
202
218
 
203
219
  def profile
204
220
  return_value = nil
221
+
205
222
  if Bullet.enable?
206
223
  begin
207
224
  Bullet.start_request
@@ -219,6 +236,14 @@ module Bullet
219
236
  return_value
220
237
  end
221
238
 
239
+ def console_enabled?
240
+ UniformNotifier.active_notifiers.include?(UniformNotifier::JavascriptConsole)
241
+ end
242
+
243
+ def skip_html_injection?
244
+ @skip_html_injection || false
245
+ end
246
+
222
247
  private
223
248
 
224
249
  def for_each_active_notifier_with_notification
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bullet
4
+ module ActiveJob
5
+ def self.included(base)
6
+ base.class_eval { around_perform { |_job, block| Bullet.profile { block.call } } }
7
+ end
8
+ end
9
+ 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,23 +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
- end
194
-
195
- ::ActiveRecord::Associations::BelongsToAssociation.class_eval do
196
- def writer_with_bullet(record)
197
- Bullet::Detector::Association.add_object_associations(owner, reflection.name) if Bullet.start?
198
- writer_without_bullet(record)
199
- end
200
- alias_method_chain :writer, :bullet
201
178
  end
202
179
  end
203
180
  end