bullet 5.4.3 → 5.6.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -96
  4. data/CHANGELOG.md +13 -7
  5. data/Gemfile +6 -1
  6. data/Gemfile.mongoid-5.0 +1 -1
  7. data/{Gemfile.mongoid-2.4 → Gemfile.mongoid-6.0} +2 -2
  8. data/Gemfile.rails-5.0 +1 -1
  9. data/{Gemfile.mongoid-2.5 → Gemfile.rails-5.1} +3 -3
  10. data/Hacking.md +1 -1
  11. data/README.md +14 -20
  12. data/lib/bullet/active_record4.rb +2 -2
  13. data/lib/bullet/active_record41.rb +5 -6
  14. data/lib/bullet/active_record42.rb +6 -19
  15. data/lib/bullet/active_record5.rb +44 -62
  16. data/lib/bullet/dependency.rb +8 -34
  17. data/lib/bullet/detector/association.rb +2 -2
  18. data/lib/bullet/detector/n_plus_one_query.rb +6 -5
  19. data/lib/bullet/ext/object.rb +1 -1
  20. data/lib/bullet/ext/string.rb +1 -1
  21. data/lib/bullet/{mongoid3x.rb → mongoid6x.rb} +3 -3
  22. data/lib/bullet/notification/base.rb +1 -1
  23. data/lib/bullet/notification/n_plus_one_query.rb +3 -3
  24. data/lib/bullet/notification/unused_eager_loading.rb +12 -7
  25. data/lib/bullet/rack.rb +7 -2
  26. data/lib/bullet/stack_trace_filter.rb +2 -1
  27. data/lib/bullet/version.rb +1 -1
  28. data/lib/generators/bullet/install_generator.rb +46 -0
  29. data/spec/bullet/detector/n_plus_one_query_spec.rb +11 -11
  30. data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
  31. data/spec/bullet/notification/unused_eager_loading_spec.rb +1 -1
  32. data/spec/integration/{active_record4 → active_record}/association_spec.rb +1 -1
  33. data/spec/integration/counter_cache_spec.rb +7 -0
  34. data/spec/support/mongo_seed.rb +2 -10
  35. data/test.sh +1 -10
  36. data/update.sh +1 -10
  37. metadata +9 -23
  38. data/Gemfile.mongoid-2.6 +0 -15
  39. data/Gemfile.mongoid-2.7 +0 -15
  40. data/Gemfile.mongoid-2.8 +0 -15
  41. data/Gemfile.mongoid-3.0 +0 -15
  42. data/Gemfile.mongoid-3.1 +0 -15
  43. data/Gemfile.rails-3.0 +0 -16
  44. data/Gemfile.rails-3.1 +0 -16
  45. data/Gemfile.rails-3.2 +0 -16
  46. data/lib/bullet/active_record3.rb +0 -238
  47. data/lib/bullet/active_record3x.rb +0 -210
  48. data/lib/bullet/mongoid2x.rb +0 -56
  49. data/spec/integration/active_record3/association_spec.rb +0 -745
  50. data/spec/integration/active_record5/association_spec.rb +0 -768
data/Gemfile.mongoid-2.8 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 2.8.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.mongoid-3.0 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 3.0.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.mongoid-3.1 DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'mongoid', '~> 3.1.0'
9
-
10
- gem "rspec"
11
-
12
- platforms :rbx do
13
- gem 'rubysl', '~> 2.0'
14
- gem 'rubinius-developer_tools'
15
- end
data/Gemfile.rails-3.0 DELETED
@@ -1,16 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.0.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'activerecord-import'
9
- gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
-
11
- gem "rspec"
12
-
13
- platforms :rbx do
14
- gem 'rubysl', '~> 2.0'
15
- gem 'rubinius-developer_tools'
16
- end
data/Gemfile.rails-3.1 DELETED
@@ -1,16 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.1.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'activerecord-import'
9
- gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
-
11
- gem "rspec"
12
-
13
- platforms :rbx do
14
- gem 'rubysl', '~> 2.0'
15
- gem 'rubinius-developer_tools'
16
- end
data/Gemfile.rails-3.2 DELETED
@@ -1,16 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'sqlite3', platforms: [:ruby]
7
- gem 'activerecord-jdbcsqlite3-adapter', platforms: [:jruby]
8
- gem 'activerecord-import'
9
- gem 'tins', '~> 1.6.0', platforms: [:ruby_19]
10
-
11
- gem "rspec"
12
-
13
- platforms :rbx do
14
- gem 'rubysl', '~> 2.0'
15
- gem 'rubinius-developer_tools'
16
- end
@@ -1,238 +0,0 @@
1
- module Bullet
2
- module ActiveRecord
3
- LOAD_TARGET = 'load_target'.freeze
4
-
5
- def self.enable
6
- require 'active_record'
7
- ::ActiveRecord::Base.class_eval do
8
- class <<self
9
- alias_method :origin_find_by_sql, :find_by_sql
10
- def find_by_sql(sql)
11
- result = origin_find_by_sql(sql)
12
- if Bullet.start?
13
- if result.is_a? Array
14
- if result.size > 1
15
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
16
- Bullet::Detector::CounterCache.add_possible_objects(result)
17
- elsif result.size == 1
18
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result.first)
19
- Bullet::Detector::CounterCache.add_impossible_object(result.first)
20
- end
21
- elsif result.is_a? ::ActiveRecord::Base
22
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
23
- Bullet::Detector::CounterCache.add_impossible_object(result)
24
- end
25
- end
26
- result
27
- end
28
- end
29
- end
30
-
31
- ::ActiveRecord::Relation.class_eval do
32
- alias_method :origin_to_a, :to_a
33
- # if select a collection of objects, then these objects have possible to cause N+1 query.
34
- # if select only one object, then the only one object has impossible to cause N+1 query.
35
- def to_a
36
- records = origin_to_a
37
- if Bullet.start?
38
- if records.size > 1
39
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
40
- Bullet::Detector::CounterCache.add_possible_objects(records)
41
- elsif records.size == 1
42
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
43
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
44
- end
45
- end
46
- records
47
- end
48
- end
49
-
50
- ::ActiveRecord::Persistence.class_eval do
51
- alias_method :origin_save, :save
52
- def save(*args, &proc)
53
- was_new_record = new_record?
54
- origin_save(*args, &proc).tap do |result|
55
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
56
- end
57
- end
58
-
59
- alias_method :origin_save!, :save!
60
- def save!(*args, &proc)
61
- was_new_record = new_record?
62
- origin_save!(*args, &proc).tap do |result|
63
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
64
- end
65
- end
66
- end
67
-
68
- ::ActiveRecord::AssociationPreload::ClassMethods.class_eval do
69
- alias_method :origin_preload_associations, :preload_associations
70
- # include query for one to many associations.
71
- # keep this eager loadings.
72
- def preload_associations(records, associations, preload_options={})
73
- if Bullet.start?
74
- records = [records].flatten.compact.uniq
75
- return if records.empty?
76
- records.each do |record|
77
- Bullet::Detector::Association.add_object_associations(record, associations)
78
- end
79
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
80
- end
81
- origin_preload_associations(records, associations, preload_options={})
82
- end
83
- end
84
-
85
- ::ActiveRecord::FinderMethods.class_eval do
86
- # add includes in scope
87
- alias_method :origin_find_with_associations, :find_with_associations
88
- def find_with_associations
89
- records = origin_find_with_associations
90
- if Bullet.start?
91
- associations = (@eager_load_values + @includes_values).uniq
92
- records.each do |record|
93
- Bullet::Detector::Association.add_object_associations(record, associations)
94
- end
95
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
96
- end
97
- records
98
- end
99
- end
100
-
101
- ::ActiveRecord::Associations::ClassMethods::JoinDependency.class_eval do
102
- alias_method :origin_instantiate, :instantiate
103
- alias_method :origin_construct_association, :construct_association
104
-
105
- def instantiate(rows)
106
- @bullet_eager_loadings = {}
107
- records = origin_instantiate(rows)
108
-
109
- if Bullet.start?
110
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
111
- objects = eager_loadings_hash.keys
112
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
113
- end
114
- end
115
- records
116
- end
117
-
118
- # call join associations
119
- def construct_association(record, join, row)
120
- result = origin_construct_association(record, join, row)
121
-
122
- if Bullet.start?
123
- associations = join.reflection.name
124
- Bullet::Detector::Association.add_object_associations(record, associations)
125
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
126
- @bullet_eager_loadings[record.class] ||= {}
127
- @bullet_eager_loadings[record.class][record] ||= Set.new
128
- @bullet_eager_loadings[record.class][record] << associations
129
- end
130
-
131
- result
132
- end
133
- end
134
-
135
- ::ActiveRecord::Associations::AssociationCollection.class_eval do
136
- # call one to many associations
137
- alias_method :origin_load_target, :load_target
138
- def load_target
139
- if Bullet.start?
140
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
141
- end
142
- origin_load_target
143
- end
144
-
145
- alias_method :origin_first, :first
146
- def first(*args)
147
- if Bullet.start?
148
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
149
- end
150
- origin_first(*args)
151
- end
152
-
153
- alias_method :origin_last, :last
154
- def last(*args)
155
- if Bullet.start?
156
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
157
- end
158
- origin_last(*args)
159
- end
160
-
161
- alias_method :origin_include?, :include?
162
- def include?(object)
163
- if Bullet.start?
164
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
165
- end
166
- origin_include?(object)
167
- end
168
- end
169
-
170
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
171
- alias_method :origin_empty?, :empty?
172
- def empty?
173
- if Bullet.start? && !has_cached_counter?
174
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
175
- end
176
- origin_empty?
177
- end
178
- end
179
-
180
- ::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
181
- alias_method :origin_empty?, :empty?
182
- def empty?
183
- if Bullet.start?
184
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
185
- end
186
- origin_empty?
187
- end
188
- end
189
-
190
- ::ActiveRecord::Associations::AssociationProxy.class_eval do
191
- # call has_one and belong_to association
192
- alias_method :origin_load_target, :load_target
193
- def load_target
194
- # avoid stack level too deep
195
- result = origin_load_target
196
- if Bullet.start?
197
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?(LOAD_TARGET) }
198
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
199
- end
200
- result
201
- end
202
-
203
- alias_method :origin_set_inverse_instance, :set_inverse_instance
204
- def set_inverse_instance(record, instance)
205
- if Bullet.start?
206
- if record && we_can_set_the_inverse_on_this?(record)
207
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
208
- end
209
- end
210
- origin_set_inverse_instance(record, instance)
211
- end
212
- end
213
-
214
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
215
- alias_method :origin_has_cached_counter?, :has_cached_counter?
216
-
217
- def has_cached_counter?
218
- result = origin_has_cached_counter?
219
- if Bullet.start? && !result
220
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
221
- end
222
- result
223
- end
224
- end
225
-
226
- ::ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
227
- alias_method :origin_has_cached_counter?, :has_cached_counter?
228
- def has_cached_counter?
229
- result = origin_has_cached_counter?
230
- if Bullet.start? && !result
231
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
232
- end
233
- result
234
- end
235
- end
236
- end
237
- end
238
- end
@@ -1,210 +0,0 @@
1
- module Bullet
2
- module ActiveRecord
3
- def self.enable
4
- require 'active_record'
5
- ::ActiveRecord::Base.class_eval do
6
- class <<self
7
- alias_method :origin_find_by_sql, :find_by_sql
8
- def find_by_sql(sql, binds = [])
9
- result = origin_find_by_sql(sql, binds)
10
- if Bullet.start?
11
- if result.is_a? Array
12
- if result.size > 1
13
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
14
- Bullet::Detector::CounterCache.add_possible_objects(result)
15
- elsif result.size == 1
16
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result.first)
17
- Bullet::Detector::CounterCache.add_impossible_object(result.first)
18
- end
19
- elsif result.is_a? ::ActiveRecord::Base
20
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
21
- Bullet::Detector::CounterCache.add_impossible_object(result)
22
- end
23
- end
24
- result
25
- end
26
- end
27
- end
28
-
29
- ::ActiveRecord::Relation.class_eval do
30
- alias_method :origin_to_a, :to_a
31
- # if select a collection of objects, then these objects have possible to cause N+1 query.
32
- # if select only one object, then the only one object has impossible to cause N+1 query.
33
- def to_a
34
- records = origin_to_a
35
- if Bullet.start?
36
- if records.size > 1
37
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
38
- Bullet::Detector::CounterCache.add_possible_objects(records)
39
- elsif records.size == 1
40
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
41
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
42
- end
43
- end
44
- records
45
- end
46
- end
47
-
48
- ::ActiveRecord::Persistence.class_eval do
49
- alias_method :origin_save, :save
50
- def save(*args, &proc)
51
- was_new_record = new_record?
52
- origin_save(*args, &proc).tap do |result|
53
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
54
- end
55
- end
56
-
57
- alias_method :origin_save!, :save!
58
- def save!(*args, &proc)
59
- was_new_record = new_record?
60
- origin_save!(*args, &proc).tap do |result|
61
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
62
- end
63
- end
64
- end
65
-
66
- ::ActiveRecord::Associations::Preloader.class_eval do
67
- # include query for one to many associations.
68
- # keep this eager loadings.
69
- alias_method :origin_initialize, :initialize
70
- def initialize(records, associations, preload_scope = nil)
71
- origin_initialize(records, associations, preload_scope)
72
- if Bullet.start?
73
- records = [records].flatten.compact.uniq
74
- return if records.empty?
75
- records.each do |record|
76
- Bullet::Detector::Association.add_object_associations(record, associations)
77
- end
78
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
79
- end
80
- end
81
- end
82
-
83
- ::ActiveRecord::FinderMethods.class_eval do
84
- # add includes in scope
85
- alias_method :origin_find_with_associations, :find_with_associations
86
- def find_with_associations
87
- records = origin_find_with_associations
88
- if Bullet.start?
89
- associations = (eager_load_values + includes_values).uniq
90
- records.each do |record|
91
- Bullet::Detector::Association.add_object_associations(record, associations)
92
- end
93
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
94
- end
95
- records
96
- end
97
- end
98
-
99
- ::ActiveRecord::Associations::JoinDependency.class_eval do
100
- alias_method :origin_instantiate, :instantiate
101
- alias_method :origin_construct_association, :construct_association
102
-
103
- def instantiate(rows)
104
- @bullet_eager_loadings = {}
105
- records = origin_instantiate(rows)
106
-
107
- if Bullet.start?
108
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
109
- objects = eager_loadings_hash.keys
110
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
111
- end
112
- end
113
- records
114
- end
115
-
116
- # call join associations
117
- def construct_association(record, join, row)
118
- result = origin_construct_association(record, join, row)
119
-
120
- if Bullet.start?
121
- associations = join.reflection.name
122
- Bullet::Detector::Association.add_object_associations(record, associations)
123
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
124
- @bullet_eager_loadings[record.class] ||= {}
125
- @bullet_eager_loadings[record.class][record] ||= Set.new
126
- @bullet_eager_loadings[record.class][record] << associations
127
- end
128
-
129
- result
130
- end
131
- end
132
-
133
- ::ActiveRecord::Associations::CollectionAssociation.class_eval do
134
- # call one to many associations
135
- alias_method :origin_load_target, :load_target
136
- def load_target
137
- if Bullet.start?
138
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
139
- end
140
- origin_load_target
141
- end
142
-
143
- alias_method :origin_include?, :include?
144
- def include?(object)
145
- if Bullet.start?
146
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
147
- end
148
- origin_include?(object)
149
- end
150
- end
151
-
152
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
153
- alias_method :origin_empty?, :empty?
154
- def empty?
155
- if Bullet.start? && !has_cached_counter?(@reflection)
156
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
157
- end
158
- origin_empty?
159
- end
160
- end
161
-
162
- ::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
163
- alias_method :origin_empty?, :empty?
164
- def empty?
165
- if Bullet.start?
166
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
167
- end
168
- origin_empty?
169
- end
170
- end
171
-
172
- ::ActiveRecord::Associations::SingularAssociation.class_eval do
173
- # call has_one and belongs_to associations
174
- alias_method :origin_reader, :reader
175
- def reader(force_reload = false)
176
- result = origin_reader(force_reload)
177
- if Bullet.start?
178
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
179
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
180
- end
181
- result
182
- end
183
- end
184
-
185
- ::ActiveRecord::Associations::Association.class_eval do
186
- alias_method :origin_set_inverse_instance, :set_inverse_instance
187
- def set_inverse_instance(record)
188
- if Bullet.start?
189
- if record && invertible_for?(record)
190
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, inverse_reflection_for(record).name)
191
- end
192
- end
193
- origin_set_inverse_instance(record)
194
- end
195
- end
196
-
197
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
198
- alias_method :origin_has_cached_counter?, :has_cached_counter?
199
-
200
- def has_cached_counter?(reflection = reflection())
201
- result = origin_has_cached_counter?(reflection)
202
- if Bullet.start? && !result
203
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
204
- end
205
- result
206
- end
207
- end
208
- end
209
- end
210
- end
@@ -1,56 +0,0 @@
1
- module Bullet
2
- module Mongoid
3
- def self.enable
4
- require 'mongoid'
5
-
6
- ::Mongoid::Contexts::Mongo.class_eval do
7
- alias_method :origin_first, :first
8
- alias_method :origin_last, :last
9
- alias_method :origin_iterate, :iterate
10
- alias_method :origin_eager_load, :eager_load
11
-
12
- def first
13
- result = origin_first
14
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
15
- result
16
- end
17
-
18
- def last
19
- result = origin_last
20
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
21
- result
22
- end
23
-
24
- def iterate(&block)
25
- records = execute.to_a
26
- if records.size > 1
27
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
28
- elsif records.size == 1
29
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
30
- end
31
- origin_iterate(&block)
32
- end
33
-
34
- def eager_load(docs)
35
- associations = criteria.inclusions.map(&:name)
36
- docs.each do |doc|
37
- Bullet::Detector::Association.add_object_associations(doc, associations)
38
- end
39
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(docs, associations)
40
- origin_eager_load(docs)
41
- end
42
- end
43
-
44
- ::Mongoid::Relations::Accessors.class_eval do
45
- alias_method :origin_set_relation, :set_relation
46
-
47
- def set_relation(name, relation)
48
- if relation && relation.metadata.macro !~ /embed/
49
- Bullet::Detector::NPlusOneQuery.call_association(self, name)
50
- end
51
- origin_set_relation(name, relation)
52
- end
53
- end
54
- end
55
- end
56
- end