bullet 7.0.7 → 7.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -2
  3. data/README.md +7 -3
  4. data/lib/bullet/active_record4.rb +21 -6
  5. data/lib/bullet/active_record41.rb +21 -6
  6. data/lib/bullet/active_record42.rb +32 -12
  7. data/lib/bullet/active_record5.rb +40 -12
  8. data/lib/bullet/active_record52.rb +40 -12
  9. data/lib/bullet/active_record60.rb +40 -12
  10. data/lib/bullet/active_record61.rb +40 -12
  11. data/lib/bullet/active_record70.rb +54 -20
  12. data/lib/bullet/active_record71.rb +318 -0
  13. data/lib/bullet/dependency.rb +12 -0
  14. data/lib/bullet/detector/n_plus_one_query.rb +2 -5
  15. data/lib/bullet/detector/unused_eager_loading.rb +5 -2
  16. data/lib/bullet/ext/object.rb +14 -3
  17. data/lib/bullet/mongoid8x.rb +59 -0
  18. data/lib/bullet/notification/base.rb +22 -10
  19. data/lib/bullet/notification/counter_cache.rb +1 -1
  20. data/lib/bullet/rack.rb +4 -2
  21. data/lib/bullet/registry/association.rb +2 -1
  22. data/lib/bullet/stack_trace_filter.rb +3 -2
  23. data/lib/bullet/version.rb +1 -1
  24. data/lib/bullet.rb +11 -2
  25. metadata +7 -155
  26. data/.github/workflows/main.yml +0 -82
  27. data/.gitignore +0 -15
  28. data/.rspec +0 -2
  29. data/Gemfile +0 -24
  30. data/Gemfile.mongoid +0 -12
  31. data/Gemfile.mongoid-4.0 +0 -15
  32. data/Gemfile.mongoid-5.0 +0 -15
  33. data/Gemfile.mongoid-6.0 +0 -15
  34. data/Gemfile.mongoid-7.0 +0 -15
  35. data/Gemfile.rails-4.0 +0 -16
  36. data/Gemfile.rails-4.1 +0 -16
  37. data/Gemfile.rails-4.2 +0 -16
  38. data/Gemfile.rails-5.0 +0 -15
  39. data/Gemfile.rails-5.1 +0 -15
  40. data/Gemfile.rails-5.2 +0 -15
  41. data/Gemfile.rails-6.0 +0 -15
  42. data/Gemfile.rails-6.1 +0 -15
  43. data/Gemfile.rails-7.0 +0 -10
  44. data/Guardfile +0 -8
  45. data/Hacking.md +0 -75
  46. data/Rakefile +0 -51
  47. data/bullet.gemspec +0 -33
  48. data/perf/benchmark.rb +0 -118
  49. data/rails/init.rb +0 -3
  50. data/spec/bullet/detector/association_spec.rb +0 -28
  51. data/spec/bullet/detector/base_spec.rb +0 -10
  52. data/spec/bullet/detector/counter_cache_spec.rb +0 -58
  53. data/spec/bullet/detector/n_plus_one_query_spec.rb +0 -150
  54. data/spec/bullet/detector/unused_eager_loading_spec.rb +0 -126
  55. data/spec/bullet/ext/object_spec.rb +0 -44
  56. data/spec/bullet/ext/string_spec.rb +0 -15
  57. data/spec/bullet/notification/base_spec.rb +0 -94
  58. data/spec/bullet/notification/counter_cache_spec.rb +0 -14
  59. data/spec/bullet/notification/n_plus_one_query_spec.rb +0 -29
  60. data/spec/bullet/notification/unused_eager_loading_spec.rb +0 -18
  61. data/spec/bullet/notification_collector_spec.rb +0 -34
  62. data/spec/bullet/rack_spec.rb +0 -296
  63. data/spec/bullet/registry/association_spec.rb +0 -28
  64. data/spec/bullet/registry/base_spec.rb +0 -46
  65. data/spec/bullet/registry/object_spec.rb +0 -26
  66. data/spec/bullet/stack_trace_filter_spec.rb +0 -26
  67. data/spec/bullet_spec.rb +0 -136
  68. data/spec/integration/active_record/association_spec.rb +0 -822
  69. data/spec/integration/counter_cache_spec.rb +0 -68
  70. data/spec/integration/mongoid/association_spec.rb +0 -246
  71. data/spec/models/address.rb +0 -5
  72. data/spec/models/attachment.rb +0 -5
  73. data/spec/models/author.rb +0 -5
  74. data/spec/models/base_user.rb +0 -7
  75. data/spec/models/category.rb +0 -12
  76. data/spec/models/city.rb +0 -5
  77. data/spec/models/client.rb +0 -8
  78. data/spec/models/comment.rb +0 -8
  79. data/spec/models/company.rb +0 -5
  80. data/spec/models/country.rb +0 -5
  81. data/spec/models/deal.rb +0 -5
  82. data/spec/models/document.rb +0 -7
  83. data/spec/models/entry.rb +0 -5
  84. data/spec/models/firm.rb +0 -7
  85. data/spec/models/folder.rb +0 -4
  86. data/spec/models/group.rb +0 -4
  87. data/spec/models/mongoid/address.rb +0 -9
  88. data/spec/models/mongoid/category.rb +0 -10
  89. data/spec/models/mongoid/comment.rb +0 -9
  90. data/spec/models/mongoid/company.rb +0 -9
  91. data/spec/models/mongoid/entry.rb +0 -9
  92. data/spec/models/mongoid/post.rb +0 -14
  93. data/spec/models/mongoid/user.rb +0 -7
  94. data/spec/models/newspaper.rb +0 -5
  95. data/spec/models/page.rb +0 -4
  96. data/spec/models/person.rb +0 -5
  97. data/spec/models/pet.rb +0 -5
  98. data/spec/models/post.rb +0 -34
  99. data/spec/models/relationship.rb +0 -6
  100. data/spec/models/reply.rb +0 -5
  101. data/spec/models/role.rb +0 -7
  102. data/spec/models/student.rb +0 -5
  103. data/spec/models/submission.rb +0 -7
  104. data/spec/models/teacher.rb +0 -5
  105. data/spec/models/user.rb +0 -8
  106. data/spec/models/writer.rb +0 -4
  107. data/spec/spec_helper.rb +0 -97
  108. data/spec/support/bullet_ext.rb +0 -56
  109. data/spec/support/mongo_seed.rb +0 -59
  110. data/spec/support/rack_double.rb +0 -49
  111. data/spec/support/sqlite_seed.rb +0 -284
  112. data/test.sh +0 -15
  113. data/update.sh +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f47e147f5df074217ee7a65123f54a1918f98bde162c7d4bf1f76bffc9f15a6
4
- data.tar.gz: e05e48b96a5e68bfbcac63f4dce4601d717ec1a32ee83a5c45aad738e1bfc48b
3
+ metadata.gz: 752fed6e96f9ea5c1baefca2e9a80ea3aefa13c279d24688f3341d18c8334afc
4
+ data.tar.gz: 78edabbca2c71e9c6d2c793bd3786d5b826f4530664aa18e7cd42cb059a85373
5
5
  SHA512:
6
- metadata.gz: 87bf095754befedb8f1137ae039191807baa1f1bcadb09c923b4f1a6abd385e73e4143e50077358a8f7155e3bf367edb1b405e3b0b260c8de5dd572699b7bafc
7
- data.tar.gz: fd692ae67a1695ee4598b24d3cd030a7f091deb42f30df0f92085b3c54f765960c0b5eabaace7b306fadf8539b514fe77076cff825c27a292c5e36f56916646b
6
+ metadata.gz: 5cad943f3641de44f17da3fe2062ed83525d0bbb1d4321208f55b4d05d6a43840f25fe0728fa4e10f42701dd8ef4eaa2322ca9ab8c8d6a2e7d7067c70d0d3186
7
+ data.tar.gz: a58309dcbfaadbb9f67352c0a1730be8397c2522ef403093fcf58a8fdcc596b45e961d39b239e40412d46d98a50033ed02398efc70df4314631bd16e220a7c88
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  ## Next Release
2
2
 
3
+ ## 7.1.6 (01/16/2024)
4
+
5
+ * Allow apps to not include the user in a notification
6
+
7
+ ## 7.1.5 (01/05/2024)
8
+
9
+ * Fix mongoid8
10
+
11
+ ## 7.1.4 (11/17/2023)
12
+
13
+ * Call association also on through reflection
14
+
15
+ ## 7.1.3 (11/05/2023)
16
+
17
+ * Call NPlusOneQuery's call_association when calling count on collection association
18
+
19
+ ## 7.1.2 (10/13/2023)
20
+
21
+ * Handle Rails 7.1 composite primary keys
22
+
23
+ ## 7.1.1 (10/07/2023)
24
+
25
+ * Add support for `Content-Security-Policy-Report-Only` nonces
26
+ * Fix count method signature
27
+
28
+ ## 7.1.0 (10/06/2023)
29
+
30
+ * Support rails 7.1
31
+ * Alias `Bullet.enable?` to `enabled?`, and `Bullet.enable=` to `enabled=`
32
+ * Added `always_append_html_body` option, so the html snippet is always included even if there are no notifications
33
+ * Added detection of n+1 count queries from `count` method
34
+ * Changed the counter cache notification title to recommend using `size`
35
+
3
36
  ## 7.0.7 (03/01/2023)
4
37
 
5
38
  * Check `Rails.application.config.content_security_policy` before insert `Bullet::Rack`
@@ -97,7 +130,7 @@
97
130
 
98
131
  * Fix through reflection for rails 5.x
99
132
  * Fix false positive in after_save/after_create callbacks
100
- * Don't triger a preload error on "manual" preloads
133
+ * Don't trigger a preload error on "manual" preloads
101
134
  * Avoid Bullet from making extra queries in mongoid6
102
135
  * Support option for #first and #last on mongoid6.x
103
136
  * Fix duplicate logs in mongoid 4.x and 5.x version
@@ -239,7 +272,7 @@
239
272
 
240
273
  ## 4.5.0 (03/24/2013)
241
274
 
242
- * Add api way to access captured associatioin
275
+ * Add api way to access captured association
243
276
  * Allow disable n_plus_one_query, unused_eager_loading and counter_cache respectively
244
277
  * Add whitelist
245
278
 
data/README.md CHANGED
@@ -101,6 +101,8 @@ The code above will enable all of the Bullet notification systems:
101
101
  item is a line number, a Range of line numbers, or a (bare) method name, to exclude only particular lines in a file.
102
102
  * `Bullet.slack`: add notifications to slack
103
103
  * `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries
104
+ * `Bullet.always_append_html_body`: always append the html body even if no notifications are present. Note: `console` or `add_footer` must also be true. Useful for Single Page Applications where the initial page load might not have any notifications present.
105
+ * `Bullet.skip_user_in_notification`: exclude the OS user (`whoami`) from notifications.
104
106
 
105
107
 
106
108
  Bullet also allows you to disable any of its detectors.
@@ -119,6 +121,8 @@ Bullet.unused_eager_loading_enable = false
119
121
  Bullet.counter_cache_enable = false
120
122
  ```
121
123
 
124
+ Note: When calling `Bullet.enable`, all other detectors are reset to their defaults (`true`) and need reconfiguring.
125
+
122
126
  ## Safe list
123
127
 
124
128
  Sometimes Bullet may notify you of query problems you don't care to fix, or
@@ -284,17 +288,17 @@ $ rails new test_bullet
284
288
  $ cd test_bullet
285
289
  $ rails g scaffold post name:string
286
290
  $ rails g scaffold comment name:string post_id:integer
287
- $ bundle exec rake db:migrate
291
+ $ bundle exec rails db:migrate
288
292
  ```
289
293
 
290
294
  2\. Change `app/models/post.rb` and `app/models/comment.rb`
291
295
 
292
296
  ```ruby
293
- class Post < ActiveRecord::Base
297
+ class Post < ApplicationRecord
294
298
  has_many :comments
295
299
  end
296
300
 
297
- class Comment < ActiveRecord::Base
301
+ class Comment < ApplicationRecord
298
302
  belongs_to :post
299
303
  end
300
304
  ```
@@ -107,12 +107,17 @@ module Bullet
107
107
  result = origin_construct_association(record, join, row)
108
108
 
109
109
  if Bullet.start?
110
- associations = join.reflection.name
111
- Bullet::Detector::Association.add_object_associations(record, associations)
112
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
113
- @bullet_eager_loadings[record.class] ||= {}
114
- @bullet_eager_loadings[record.class][record] ||= Set.new
115
- @bullet_eager_loadings[record.class][record] << associations
110
+ associations = [join.reflection.name]
111
+ if join.reflection.nested?
112
+ associations << join.reflection.through_reflection.name
113
+ end
114
+ associations.each do |association|
115
+ Bullet::Detector::Association.add_object_associations(record, association)
116
+ Bullet::Detector::NPlusOneQuery.call_association(record, association)
117
+ @bullet_eager_loadings[record.class] ||= {}
118
+ @bullet_eager_loadings[record.class][record] ||= Set.new
119
+ @bullet_eager_loadings[record.class][record] << association
120
+ end
116
121
  end
117
122
 
118
123
  result
@@ -176,6 +181,16 @@ module Bullet
176
181
  result
177
182
  end
178
183
  end
184
+
185
+ ::ActiveRecord::Associations::CollectionProxy.class_eval do
186
+ def count(column_name = nil, options = {})
187
+ if Bullet.start?
188
+ Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
189
+ Bullet::Detector::NPlusOneQuery.call_association(proxy_association.owner, proxy_association.reflection.name)
190
+ end
191
+ super(column_name, options)
192
+ end
193
+ end
179
194
  end
180
195
  end
181
196
  end
@@ -110,12 +110,17 @@ module Bullet
110
110
  result = origin_construct_model(record, node, row, model_cache, id, aliases)
111
111
 
112
112
  if Bullet.start?
113
- associations = node.reflection.name
114
- Bullet::Detector::Association.add_object_associations(record, associations)
115
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
116
- @bullet_eager_loadings[record.class] ||= {}
117
- @bullet_eager_loadings[record.class][record] ||= Set.new
118
- @bullet_eager_loadings[record.class][record] << associations
113
+ associations = [node.reflection.name]
114
+ if node.reflection.nested?
115
+ associations << node.reflection.through_reflection.name
116
+ end
117
+ associations.each do |association|
118
+ Bullet::Detector::Association.add_object_associations(record, association)
119
+ Bullet::Detector::NPlusOneQuery.call_association(record, association)
120
+ @bullet_eager_loadings[record.class] ||= {}
121
+ @bullet_eager_loadings[record.class][record] ||= Set.new
122
+ @bullet_eager_loadings[record.class][record] << association
123
+ end
119
124
  end
120
125
 
121
126
  result
@@ -168,6 +173,16 @@ module Bullet
168
173
  origin_count_records
169
174
  end
170
175
  end
176
+
177
+ ::ActiveRecord::Associations::CollectionProxy.class_eval do
178
+ def count(column_name = nil, options = {})
179
+ if Bullet.start?
180
+ Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
181
+ Bullet::Detector::NPlusOneQuery.call_association(proxy_association.owner, proxy_association.reflection.name)
182
+ end
183
+ super(column_name, options)
184
+ end
185
+ end
171
186
  end
172
187
  end
173
188
  end
@@ -129,12 +129,17 @@ module Bullet
129
129
  id = row[key]
130
130
  next unless id.nil?
131
131
 
132
- associations = node.reflection.name
133
- Bullet::Detector::Association.add_object_associations(ar_parent, associations)
134
- Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
135
- @bullet_eager_loadings[ar_parent.class] ||= {}
136
- @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
137
- @bullet_eager_loadings[ar_parent.class][ar_parent] << associations
132
+ associations = [node.reflection.name]
133
+ if node.reflection.nested?
134
+ associations << node.reflection.through_reflection.name
135
+ end
136
+ associations.each do |association|
137
+ Bullet::Detector::Association.add_object_associations(ar_parent, association)
138
+ Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
139
+ @bullet_eager_loadings[ar_parent.class] ||= {}
140
+ @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
141
+ @bullet_eager_loadings[ar_parent.class][ar_parent] << association
142
+ end
138
143
  end
139
144
  end
140
145
  end
@@ -147,12 +152,17 @@ module Bullet
147
152
  result = origin_construct_model(record, node, row, model_cache, id, aliases)
148
153
 
149
154
  if Bullet.start?
150
- associations = node.reflection.name
151
- Bullet::Detector::Association.add_object_associations(record, associations)
152
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
153
- @bullet_eager_loadings[record.class] ||= {}
154
- @bullet_eager_loadings[record.class][record] ||= Set.new
155
- @bullet_eager_loadings[record.class][record] << associations
155
+ associations = [node.reflection.name]
156
+ if node.reflection.nested?
157
+ associations << node.reflection.through_reflection.name
158
+ end
159
+ associations.each do |association|
160
+ Bullet::Detector::Association.add_object_associations(record, association)
161
+ Bullet::Detector::NPlusOneQuery.call_association(record, association)
162
+ @bullet_eager_loadings[record.class] ||= {}
163
+ @bullet_eager_loadings[record.class][record] ||= Set.new
164
+ @bullet_eager_loadings[record.class][record] << association
165
+ end
156
166
  end
157
167
 
158
168
  result
@@ -233,6 +243,16 @@ module Bullet
233
243
  origin_count_records
234
244
  end
235
245
  end
246
+
247
+ ::ActiveRecord::Associations::CollectionProxy.class_eval do
248
+ def count(column_name = nil, options = {})
249
+ if Bullet.start?
250
+ Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
251
+ Bullet::Detector::NPlusOneQuery.call_association(proxy_association.owner, proxy_association.reflection.name)
252
+ end
253
+ super(column_name, options)
254
+ end
255
+ end
236
256
  end
237
257
  end
238
258
  end
@@ -138,12 +138,17 @@ module Bullet
138
138
  id = row[key]
139
139
  next unless id.nil?
140
140
 
141
- associations = node.reflection.name
142
- Bullet::Detector::Association.add_object_associations(ar_parent, associations)
143
- Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
144
- @bullet_eager_loadings[ar_parent.class] ||= {}
145
- @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
146
- @bullet_eager_loadings[ar_parent.class][ar_parent] << associations
141
+ associations = [node.reflection.name]
142
+ if node.reflection.through_reflection?
143
+ associations << node.reflection.through_reflection.name
144
+ end
145
+ associations.each do |association|
146
+ Bullet::Detector::Association.add_object_associations(ar_parent, association)
147
+ Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
148
+ @bullet_eager_loadings[ar_parent.class] ||= {}
149
+ @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
150
+ @bullet_eager_loadings[ar_parent.class][ar_parent] << association
151
+ end
147
152
  end
148
153
  end
149
154
  end
@@ -156,12 +161,17 @@ module Bullet
156
161
  result = super
157
162
 
158
163
  if Bullet.start?
159
- associations = node.reflection.name
160
- Bullet::Detector::Association.add_object_associations(record, associations)
161
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
162
- @bullet_eager_loadings[record.class] ||= {}
163
- @bullet_eager_loadings[record.class][record] ||= Set.new
164
- @bullet_eager_loadings[record.class][record] << associations
164
+ associations = [node.reflection.name]
165
+ if node.reflection.through_reflection?
166
+ associations << node.reflection.through_reflection.name
167
+ end
168
+ associations.each do |association|
169
+ Bullet::Detector::Association.add_object_associations(record, association)
170
+ Bullet::Detector::NPlusOneQuery.call_association(record, association)
171
+ @bullet_eager_loadings[record.class] ||= {}
172
+ @bullet_eager_loadings[record.class][record] ||= Set.new
173
+ @bullet_eager_loadings[record.class][record] << association
174
+ end
165
175
  end
166
176
 
167
177
  result
@@ -260,6 +270,24 @@ module Bullet
260
270
  end
261
271
  end
262
272
  )
273
+
274
+ ::ActiveRecord::Associations::CollectionProxy.prepend(
275
+ Module.new do
276
+ def count
277
+ if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
278
+ Bullet::Detector::CounterCache.add_counter_cache(
279
+ proxy_association.owner,
280
+ proxy_association.reflection.name
281
+ )
282
+ Bullet::Detector::NPlusOneQuery.call_association(
283
+ proxy_association.owner,
284
+ proxy_association.reflection.name
285
+ )
286
+ end
287
+ super
288
+ end
289
+ end
290
+ )
263
291
  end
264
292
  end
265
293
  end
@@ -101,12 +101,17 @@ module Bullet
101
101
  id = row[key]
102
102
  next unless id.nil?
103
103
 
104
- associations = node.reflection.name
105
- Bullet::Detector::Association.add_object_associations(ar_parent, associations)
106
- Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
107
- @bullet_eager_loadings[ar_parent.class] ||= {}
108
- @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
109
- @bullet_eager_loadings[ar_parent.class][ar_parent] << associations
104
+ associations = [node.reflection.name]
105
+ if node.reflection.through_reflection?
106
+ associations << node.reflection.through_reflection.name
107
+ end
108
+ associations.each do |association|
109
+ Bullet::Detector::Association.add_object_associations(ar_parent, association)
110
+ Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
111
+ @bullet_eager_loadings[ar_parent.class] ||= {}
112
+ @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
113
+ @bullet_eager_loadings[ar_parent.class][ar_parent] << association
114
+ end
110
115
  end
111
116
  end
112
117
  end
@@ -119,12 +124,17 @@ module Bullet
119
124
  result = super
120
125
 
121
126
  if Bullet.start?
122
- associations = node.reflection.name
123
- Bullet::Detector::Association.add_object_associations(record, associations)
124
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
125
- @bullet_eager_loadings[record.class] ||= {}
126
- @bullet_eager_loadings[record.class][record] ||= Set.new
127
- @bullet_eager_loadings[record.class][record] << associations
127
+ associations = [node.reflection.name]
128
+ if node.reflection.through_reflection?
129
+ associations << node.reflection.through_reflection.name
130
+ end
131
+ associations.each do |association|
132
+ Bullet::Detector::Association.add_object_associations(record, association)
133
+ Bullet::Detector::NPlusOneQuery.call_association(record, association)
134
+ @bullet_eager_loadings[record.class] ||= {}
135
+ @bullet_eager_loadings[record.class][record] ||= Set.new
136
+ @bullet_eager_loadings[record.class][record] << association
137
+ end
128
138
  end
129
139
 
130
140
  result
@@ -242,6 +252,24 @@ module Bullet
242
252
  end
243
253
  end
244
254
  )
255
+
256
+ ::ActiveRecord::Associations::CollectionProxy.prepend(
257
+ Module.new do
258
+ def count(column_name = nil)
259
+ if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
260
+ Bullet::Detector::CounterCache.add_counter_cache(
261
+ proxy_association.owner,
262
+ proxy_association.reflection.name
263
+ )
264
+ Bullet::Detector::NPlusOneQuery.call_association(
265
+ proxy_association.owner,
266
+ proxy_association.reflection.name
267
+ )
268
+ end
269
+ super(column_name)
270
+ end
271
+ end
272
+ )
245
273
  end
246
274
  end
247
275
  end
@@ -128,12 +128,17 @@ module Bullet
128
128
  id = row[key]
129
129
  next unless id.nil?
130
130
 
131
- associations = node.reflection.name
132
- Bullet::Detector::Association.add_object_associations(ar_parent, associations)
133
- Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
134
- @bullet_eager_loadings[ar_parent.class] ||= {}
135
- @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
136
- @bullet_eager_loadings[ar_parent.class][ar_parent] << associations
131
+ associations = [node.reflection.name]
132
+ if node.reflection.through_reflection?
133
+ associations << node.reflection.through_reflection.name
134
+ end
135
+ associations.each do |association|
136
+ Bullet::Detector::Association.add_object_associations(ar_parent, association)
137
+ Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
138
+ @bullet_eager_loadings[ar_parent.class] ||= {}
139
+ @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
140
+ @bullet_eager_loadings[ar_parent.class][ar_parent] << association
141
+ end
137
142
  end
138
143
  end
139
144
  end
@@ -146,12 +151,17 @@ module Bullet
146
151
  result = super
147
152
 
148
153
  if Bullet.start?
149
- associations = node.reflection.name
150
- Bullet::Detector::Association.add_object_associations(record, associations)
151
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
152
- @bullet_eager_loadings[record.class] ||= {}
153
- @bullet_eager_loadings[record.class][record] ||= Set.new
154
- @bullet_eager_loadings[record.class][record] << associations
154
+ associations = [node.reflection.name]
155
+ if node.reflection.through_reflection?
156
+ associations << node.reflection.through_reflection.name
157
+ end
158
+ associations.each do |association|
159
+ Bullet::Detector::Association.add_object_associations(record, association)
160
+ Bullet::Detector::NPlusOneQuery.call_association(record, association)
161
+ @bullet_eager_loadings[record.class] ||= {}
162
+ @bullet_eager_loadings[record.class][record] ||= Set.new
163
+ @bullet_eager_loadings[record.class][record] << association
164
+ end
155
165
  end
156
166
 
157
167
  result
@@ -269,6 +279,24 @@ module Bullet
269
279
  end
270
280
  end
271
281
  )
282
+
283
+ ::ActiveRecord::Associations::CollectionProxy.prepend(
284
+ Module.new do
285
+ def count
286
+ if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
287
+ Bullet::Detector::CounterCache.add_counter_cache(
288
+ proxy_association.owner,
289
+ proxy_association.reflection.name
290
+ )
291
+ Bullet::Detector::NPlusOneQuery.call_association(
292
+ proxy_association.owner,
293
+ proxy_association.reflection.name
294
+ )
295
+ end
296
+ super
297
+ end
298
+ end
299
+ )
272
300
  end
273
301
  end
274
302
  end
@@ -128,12 +128,17 @@ module Bullet
128
128
  id = row[key]
129
129
  next unless id.nil?
130
130
 
131
- associations = node.reflection.name
132
- Bullet::Detector::Association.add_object_associations(ar_parent, associations)
133
- Bullet::Detector::NPlusOneQuery.call_association(ar_parent, associations)
134
- @bullet_eager_loadings[ar_parent.class] ||= {}
135
- @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
136
- @bullet_eager_loadings[ar_parent.class][ar_parent] << associations
131
+ associations = [node.reflection.name]
132
+ if node.reflection.through_reflection?
133
+ associations << node.reflection.through_reflection.name
134
+ end
135
+ associations.each do |association|
136
+ Bullet::Detector::Association.add_object_associations(ar_parent, association)
137
+ Bullet::Detector::NPlusOneQuery.call_association(ar_parent, association)
138
+ @bullet_eager_loadings[ar_parent.class] ||= {}
139
+ @bullet_eager_loadings[ar_parent.class][ar_parent] ||= Set.new
140
+ @bullet_eager_loadings[ar_parent.class][ar_parent] << association
141
+ end
137
142
  end
138
143
  end
139
144
  end
@@ -146,12 +151,17 @@ module Bullet
146
151
  result = super
147
152
 
148
153
  if Bullet.start?
149
- associations = node.reflection.name
150
- Bullet::Detector::Association.add_object_associations(record, associations)
151
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
152
- @bullet_eager_loadings[record.class] ||= {}
153
- @bullet_eager_loadings[record.class][record] ||= Set.new
154
- @bullet_eager_loadings[record.class][record] << associations
154
+ associations = [node.reflection.name]
155
+ if node.reflection.through_reflection?
156
+ associations << node.reflection.through_reflection.name
157
+ end
158
+ associations.each do |association|
159
+ Bullet::Detector::Association.add_object_associations(record, association)
160
+ Bullet::Detector::NPlusOneQuery.call_association(record, association)
161
+ @bullet_eager_loadings[record.class] ||= {}
162
+ @bullet_eager_loadings[record.class][record] ||= Set.new
163
+ @bullet_eager_loadings[record.class][record] << association
164
+ end
155
165
  end
156
166
 
157
167
  result
@@ -269,6 +279,24 @@ module Bullet
269
279
  end
270
280
  end
271
281
  )
282
+
283
+ ::ActiveRecord::Associations::CollectionProxy.prepend(
284
+ Module.new do
285
+ def count(column_name = nil)
286
+ if Bullet.start? && !proxy_association.is_a?(::ActiveRecord::Associations::ThroughAssociation)
287
+ Bullet::Detector::CounterCache.add_counter_cache(
288
+ proxy_association.owner,
289
+ proxy_association.reflection.name
290
+ )
291
+ Bullet::Detector::NPlusOneQuery.call_association(
292
+ proxy_association.owner,
293
+ proxy_association.reflection.name
294
+ )
295
+ end
296
+ super(column_name)
297
+ end
298
+ end
299
+ )
272
300
  end
273
301
  end
274
302
  end