bullet 6.0.1 → 6.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -1
  3. data/CHANGELOG.md +25 -0
  4. data/Gemfile.rails-6.0 +1 -1
  5. data/Gemfile.rails-6.1 +15 -0
  6. data/README.md +12 -3
  7. data/lib/bullet.rb +30 -19
  8. data/lib/bullet/active_job.rb +1 -3
  9. data/lib/bullet/active_record4.rb +9 -23
  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 +187 -161
  14. data/lib/bullet/active_record60.rb +204 -171
  15. data/lib/bullet/active_record61.rb +278 -0
  16. data/lib/bullet/bullet_xhr.js +17 -23
  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 +3 -7
  24. data/lib/bullet/mongoid5x.rb +3 -7
  25. data/lib/bullet/mongoid6x.rb +3 -7
  26. data/lib/bullet/mongoid7x.rb +3 -7
  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 +22 -14
  31. data/lib/bullet/stack_trace_filter.rb +5 -11
  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 +77 -7
  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 +77 -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/attachment.rb +5 -0
  49. data/spec/models/folder.rb +1 -2
  50. data/spec/models/group.rb +1 -2
  51. data/spec/models/page.rb +1 -2
  52. data/spec/models/submission.rb +1 -0
  53. data/spec/models/user.rb +1 -0
  54. data/spec/models/writer.rb +1 -2
  55. data/spec/spec_helper.rb +6 -10
  56. data/spec/support/bullet_ext.rb +8 -9
  57. data/spec/support/mongo_seed.rb +2 -16
  58. data/spec/support/sqlite_seed.rb +8 -0
  59. metadata +10 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f255102db3ae1250632db2b30a9e6f1bce87dab49b4dabee73709ffde82a4e0
4
- data.tar.gz: 025ab0e3513546a56e984aa83a0b925d27e631bdfe61feb694b3e21ecfb6ffda
3
+ metadata.gz: b574ae38dafed75dc9aded2d6c97ab057593fcda5a49ec4875bc327f99625efd
4
+ data.tar.gz: df882c895e98b91a26371b670ffd439a2a39e80df57ce1b61a87de6e89c10c1a
5
5
  SHA512:
6
- metadata.gz: 23d701691dc1f2286ec11ffb26f548878bfa7ddd2ea8f20d97bb4c64df4e3a7a10f54adb16fa7cacd8bb8807dd1804e349c1b889e32530cbb7c57432ceec17da
7
- data.tar.gz: 281a4a6619695a7db4098f1ed62066cd4e81cf9c2c3bf33fa83f87a205a5c4779e9c8125143a78ca482247ed2a271465b3011af84a5dfc67753cbad2357ee2ae
6
+ metadata.gz: 475691616eca228e0938effbc8a9a8930d8ab33f673d4cb2a75ff02b2933ba01ee2a570fff1d9d669700fb05cf09dff9149555f1f2b35c4a31c8904620db70e3
7
+ data.tar.gz: 86f37317790084aa7ca3860c1757a41354678a1a0bfbf56fe6f21ebe6793eef5ff257fe75bbad77b999484a9e1abb527d9e9ac877dda04cf9f1236e110e6d561
@@ -1,4 +1,3 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.3.0
@@ -29,3 +28,6 @@ matrix:
29
28
  gemfile: Gemfile.rails-4.0
30
29
  env:
31
30
  - DB=sqlite
31
+ before_install:
32
+ - "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
33
+ - gem install bundler -v '< 2'
@@ -1,5 +1,30 @@
1
1
  ## Next Release
2
2
 
3
+ ## 6.1.3 (01/21/2021)
4
+
5
+ * Consider ThroughAssociation at SingularAssociation like CollectionAssociation
6
+ * Add xhr_script only when add_footer is enabled
7
+
8
+ ## 6.1.2 (12/12/2020)
9
+
10
+ * Revert "Make whitelist thread safe"
11
+
12
+ ## 6.1.1 (12/12/2020)
13
+
14
+ * Add support Rails 6.1
15
+ * Make whitelist thread safe
16
+
17
+ ## 6.1.0 (12/28/2019)
18
+
19
+ * Add skip_html_injection flag
20
+ * Remove writer hack in active_record6
21
+ * Use modern includes syntax in warnings
22
+ * Fix warning: The last argument is used as the keyword parameter
23
+
24
+ ## 6.0.2 (08/20/2019)
25
+
26
+ * Fully support Rails 6.0
27
+
3
28
  ## 6.0.1 (06/26/2019)
4
29
 
5
30
  * Add Bullet::ActiveJob
@@ -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?
@@ -23,7 +23,7 @@ module Bullet
23
23
  BULLET_DEBUG = 'BULLET_DEBUG'
24
24
  TRUE = 'true'
25
25
 
26
- if defined? Rails::Railtie
26
+ if defined?(Rails::Railtie)
27
27
  class BulletRailtie < Rails::Railtie
28
28
  initializer 'bullet.configure_rails_initialization' do |app|
29
29
  app.middleware.use Bullet::Rack
@@ -32,28 +32,36 @@ module Bullet
32
32
  end
33
33
 
34
34
  class << self
35
- 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
36
41
  attr_reader :whitelist
37
- attr_accessor :add_footer, :orm_pathches_applied
42
+ attr_accessor :add_footer, :orm_patches_applied
38
43
 
39
- available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.map { |notifier| "#{notifier}=" }
40
- available_notifiers << { to: UniformNotifier }
41
- delegate(*available_notifiers)
44
+ available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise }.map { |notifier| "#{notifier}=" }
45
+ available_notifiers_options = { to: UniformNotifier }
46
+ delegate(*available_notifiers, **available_notifiers_options)
42
47
 
43
48
  def raise=(should_raise)
44
49
  UniformNotifier.raise = (should_raise ? Notification::UnoptimizedQueryError : false)
45
50
  end
46
51
 
47
- DETECTORS = [Bullet::Detector::NPlusOneQuery,
48
- Bullet::Detector::UnusedEagerLoading,
49
- Bullet::Detector::CounterCache].freeze
52
+ DETECTORS = [
53
+ Bullet::Detector::NPlusOneQuery,
54
+ Bullet::Detector::UnusedEagerLoading,
55
+ Bullet::Detector::CounterCache
56
+ ].freeze
50
57
 
51
58
  def enable=(enable)
52
59
  @enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable
60
+
53
61
  if enable?
54
62
  reset_whitelist
55
- unless orm_pathches_applied
56
- self.orm_pathches_applied = true
63
+ unless orm_patches_applied
64
+ self.orm_patches_applied = true
57
65
  Bullet::Mongoid.enable if mongoid?
58
66
  Bullet::ActiveRecord.enable if active_record?
59
67
  end
@@ -81,11 +89,11 @@ module Bullet
81
89
  end
82
90
 
83
91
  def stacktrace_includes
84
- @stacktrace_includes || []
92
+ @stacktrace_includes ||= []
85
93
  end
86
94
 
87
95
  def stacktrace_excludes
88
- @stacktrace_excludes || []
96
+ @stacktrace_excludes ||= []
89
97
  end
90
98
 
91
99
  def add_whitelist(options)
@@ -174,9 +182,7 @@ module Bullet
174
182
 
175
183
  def gather_inline_notifications
176
184
  responses = []
177
- for_each_active_notifier_with_notification do |notification|
178
- responses << notification.notify_inline
179
- end
185
+ for_each_active_notifier_with_notification { |notification| responses << notification.notify_inline }
180
186
  responses.join("\n")
181
187
  end
182
188
 
@@ -190,9 +196,7 @@ module Bullet
190
196
 
191
197
  def footer_info
192
198
  info = []
193
- notification_collector.collection.each do |notification|
194
- info << notification.short_notice
195
- end
199
+ notification_collector.collection.each { |notification| info << notification.short_notice }
196
200
  info
197
201
  end
198
202
 
@@ -214,6 +218,7 @@ module Bullet
214
218
 
215
219
  def profile
216
220
  return_value = nil
221
+
217
222
  if Bullet.enable?
218
223
  begin
219
224
  Bullet.start_request
@@ -235,6 +240,12 @@ module Bullet
235
240
  UniformNotifier.active_notifiers.include?(UniformNotifier::JavascriptConsole)
236
241
  end
237
242
 
243
+ def inject_into_page?
244
+ return false if defined?(@skip_html_injection) && @skip_html_injection
245
+
246
+ console_enabled? || add_footer
247
+ end
248
+
238
249
  private
239
250
 
240
251
  def for_each_active_notifier_with_notification
@@ -5,9 +5,7 @@ module Bullet
5
5
  def self.included(base)
6
6
  base.class_eval do
7
7
  around_perform do |_job, block|
8
- Bullet.profile do
9
- block.call
10
- end
8
+ Bullet.profile { block.call }
11
9
  end
12
10
  end
13
11
  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
@@ -183,12 +172,9 @@ module Bullet
183
172
 
184
173
  def has_cached_counter?(reflection = reflection())
185
174
  result = origin_has_cached_counter?(reflection)
186
- if Bullet.start? && !result
187
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
188
- end
175
+ Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) if Bullet.start? && !result
189
176
  result
190
177
  end
191
-
192
178
  end
193
179
  end
194
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
@@ -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, :find
10
10
  def find(*args)
11
11
  result = origin_find(*args)
@@ -45,9 +45,7 @@ module Bullet
45
45
 
46
46
  ::ActiveRecord::Persistence.class_eval do
47
47
  def _create_record_with_bullet(*args)
48
- _create_record_without_bullet(*args).tap do
49
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
50
- end
48
+ _create_record_without_bullet(*args).tap { Bullet::Detector::NPlusOneQuery.add_impossible_object(self) }
51
49
  end
52
50
  alias_method_chain :_create_record, :bullet
53
51
  end
@@ -80,9 +78,7 @@ module Bullet
80
78
  if Bullet.start?
81
79
  records.compact!
82
80
  if records.first.class.name !~ /^HABTM_/
83
- records.each do |record|
84
- Bullet::Detector::Association.add_object_associations(record, association)
85
- end
81
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, association) }
86
82
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
87
83
  end
88
84
  end
@@ -99,9 +95,7 @@ module Bullet
99
95
  records = origin_find_with_associations
100
96
  if Bullet.start?
101
97
  associations = (eager_load_values + includes_values).uniq
102
- records.each do |record|
103
- Bullet::Detector::Association.add_object_associations(record, associations)
104
- end
98
+ records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
105
99
  Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
106
100
  end
107
101
  records
@@ -195,9 +189,7 @@ module Bullet
195
189
 
196
190
  alias_method :origin_include?, :include?
197
191
  def include?(object)
198
- if Bullet.start?
199
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
200
- end
192
+ Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
201
193
  origin_include?(object)
202
194
  end
203
195
  end
@@ -207,9 +199,11 @@ module Bullet
207
199
  alias_method :origin_reader, :reader
208
200
  def reader(force_reload = false)
209
201
  result = origin_reader(force_reload)
202
+
210
203
  if Bullet.start?
211
204
  if @owner.class.name !~ /^HABTM_/ && !@inversed
212
205
  Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
206
+
213
207
  if Bullet::Detector::NPlusOneQuery.impossible?(@owner)
214
208
  Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
215
209
  else
@@ -234,9 +228,7 @@ module Bullet
234
228
  alias_method :origin_count_records, :count_records
235
229
  def count_records
236
230
  result = has_cached_counter?
237
- if Bullet.start? && !result
238
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
239
- end
231
+ Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) if Bullet.start? && !result
240
232
  origin_count_records
241
233
  end
242
234
  end