bullet 5.4.2 → 5.5.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.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.2
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -51,18 +51,9 @@ files:
51
51
  - CHANGELOG.md
52
52
  - Gemfile
53
53
  - Gemfile.mongoid
54
- - Gemfile.mongoid-2.4
55
- - Gemfile.mongoid-2.5
56
- - Gemfile.mongoid-2.6
57
- - Gemfile.mongoid-2.7
58
- - Gemfile.mongoid-2.8
59
- - Gemfile.mongoid-3.0
60
- - Gemfile.mongoid-3.1
61
54
  - Gemfile.mongoid-4.0
62
55
  - Gemfile.mongoid-5.0
63
- - Gemfile.rails-3.0
64
- - Gemfile.rails-3.1
65
- - Gemfile.rails-3.2
56
+ - Gemfile.mongoid-6.0
66
57
  - Gemfile.rails-4.0
67
58
  - Gemfile.rails-4.1
68
59
  - Gemfile.rails-4.2
@@ -74,8 +65,6 @@ files:
74
65
  - Rakefile
75
66
  - bullet.gemspec
76
67
  - lib/bullet.rb
77
- - lib/bullet/active_record3.rb
78
- - lib/bullet/active_record3x.rb
79
68
  - lib/bullet/active_record4.rb
80
69
  - lib/bullet/active_record41.rb
81
70
  - lib/bullet/active_record42.rb
@@ -89,10 +78,9 @@ files:
89
78
  - lib/bullet/detector/unused_eager_loading.rb
90
79
  - lib/bullet/ext/object.rb
91
80
  - lib/bullet/ext/string.rb
92
- - lib/bullet/mongoid2x.rb
93
- - lib/bullet/mongoid3x.rb
94
81
  - lib/bullet/mongoid4x.rb
95
82
  - lib/bullet/mongoid5x.rb
83
+ - lib/bullet/mongoid6x.rb
96
84
  - lib/bullet/notification.rb
97
85
  - lib/bullet/notification/base.rb
98
86
  - lib/bullet/notification/counter_cache.rb
@@ -125,7 +113,6 @@ files:
125
113
  - spec/bullet/registry/base_spec.rb
126
114
  - spec/bullet/registry/object_spec.rb
127
115
  - spec/bullet_spec.rb
128
- - spec/integration/active_record3/association_spec.rb
129
116
  - spec/integration/active_record4/association_spec.rb
130
117
  - spec/integration/active_record5/association_spec.rb
131
118
  - spec/integration/counter_cache_spec.rb
@@ -212,7 +199,6 @@ test_files:
212
199
  - spec/bullet/registry/base_spec.rb
213
200
  - spec/bullet/registry/object_spec.rb
214
201
  - spec/bullet_spec.rb
215
- - spec/integration/active_record3/association_spec.rb
216
202
  - spec/integration/active_record4/association_spec.rb
217
203
  - spec/integration/active_record5/association_spec.rb
218
204
  - spec/integration/counter_cache_spec.rb
data/Gemfile.mongoid-2.5 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.5.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-2.6 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.6.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-2.7 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.7.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-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,233 +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
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
15
- Bullet::Detector::CounterCache.add_possible_objects(result)
16
- elsif result.is_a? ::ActiveRecord::Base
17
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
18
- Bullet::Detector::CounterCache.add_impossible_object(result)
19
- end
20
- end
21
- result
22
- end
23
- end
24
- end
25
-
26
- ::ActiveRecord::Relation.class_eval do
27
- alias_method :origin_to_a, :to_a
28
- # if select a collection of objects, then these objects have possible to cause N+1 query.
29
- # if select only one object, then the only one object has impossible to cause N+1 query.
30
- def to_a
31
- records = origin_to_a
32
- if Bullet.start?
33
- if records.size > 1
34
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
35
- Bullet::Detector::CounterCache.add_possible_objects(records)
36
- elsif records.size == 1
37
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
38
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
39
- end
40
- end
41
- records
42
- end
43
- end
44
-
45
- ::ActiveRecord::Persistence.class_eval do
46
- alias_method :origin_save, :save
47
- def save(*args, &proc)
48
- was_new_record = new_record?
49
- origin_save(*args, &proc).tap do |result|
50
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
51
- end
52
- end
53
-
54
- alias_method :origin_save!, :save!
55
- def save!(*args, &proc)
56
- was_new_record = new_record?
57
- origin_save!(*args, &proc).tap do |result|
58
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
59
- end
60
- end
61
- end
62
-
63
- ::ActiveRecord::AssociationPreload::ClassMethods.class_eval do
64
- alias_method :origin_preload_associations, :preload_associations
65
- # include query for one to many associations.
66
- # keep this eager loadings.
67
- def preload_associations(records, associations, preload_options={})
68
- if Bullet.start?
69
- records = [records].flatten.compact.uniq
70
- return if records.empty?
71
- records.each do |record|
72
- Bullet::Detector::Association.add_object_associations(record, associations)
73
- end
74
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
75
- end
76
- origin_preload_associations(records, associations, preload_options={})
77
- end
78
- end
79
-
80
- ::ActiveRecord::FinderMethods.class_eval do
81
- # add includes in scope
82
- alias_method :origin_find_with_associations, :find_with_associations
83
- def find_with_associations
84
- records = origin_find_with_associations
85
- if Bullet.start?
86
- associations = (@eager_load_values + @includes_values).uniq
87
- records.each do |record|
88
- Bullet::Detector::Association.add_object_associations(record, associations)
89
- end
90
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
91
- end
92
- records
93
- end
94
- end
95
-
96
- ::ActiveRecord::Associations::ClassMethods::JoinDependency.class_eval do
97
- alias_method :origin_instantiate, :instantiate
98
- alias_method :origin_construct_association, :construct_association
99
-
100
- def instantiate(rows)
101
- @bullet_eager_loadings = {}
102
- records = origin_instantiate(rows)
103
-
104
- if Bullet.start?
105
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
106
- objects = eager_loadings_hash.keys
107
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
108
- end
109
- end
110
- records
111
- end
112
-
113
- # call join associations
114
- def construct_association(record, join, row)
115
- result = origin_construct_association(record, join, row)
116
-
117
- if Bullet.start?
118
- associations = join.reflection.name
119
- Bullet::Detector::Association.add_object_associations(record, associations)
120
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
121
- @bullet_eager_loadings[record.class] ||= {}
122
- @bullet_eager_loadings[record.class][record] ||= Set.new
123
- @bullet_eager_loadings[record.class][record] << associations
124
- end
125
-
126
- result
127
- end
128
- end
129
-
130
- ::ActiveRecord::Associations::AssociationCollection.class_eval do
131
- # call one to many associations
132
- alias_method :origin_load_target, :load_target
133
- def load_target
134
- if Bullet.start?
135
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
136
- end
137
- origin_load_target
138
- end
139
-
140
- alias_method :origin_first, :first
141
- def first(*args)
142
- if Bullet.start?
143
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
144
- end
145
- origin_first(*args)
146
- end
147
-
148
- alias_method :origin_last, :last
149
- def last(*args)
150
- if Bullet.start?
151
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
152
- end
153
- origin_last(*args)
154
- end
155
-
156
- alias_method :origin_include?, :include?
157
- def include?(object)
158
- if Bullet.start?
159
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
160
- end
161
- origin_include?(object)
162
- end
163
- end
164
-
165
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
166
- alias_method :origin_empty?, :empty?
167
- def empty?
168
- if Bullet.start? && !has_cached_counter?
169
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
170
- end
171
- origin_empty?
172
- end
173
- end
174
-
175
- ::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
176
- alias_method :origin_empty?, :empty?
177
- def empty?
178
- if Bullet.start?
179
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
180
- end
181
- origin_empty?
182
- end
183
- end
184
-
185
- ::ActiveRecord::Associations::AssociationProxy.class_eval do
186
- # call has_one and belong_to association
187
- alias_method :origin_load_target, :load_target
188
- def load_target
189
- # avoid stack level too deep
190
- result = origin_load_target
191
- if Bullet.start?
192
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?(LOAD_TARGET) }
193
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
194
- end
195
- result
196
- end
197
-
198
- alias_method :origin_set_inverse_instance, :set_inverse_instance
199
- def set_inverse_instance(record, instance)
200
- if Bullet.start?
201
- if record && we_can_set_the_inverse_on_this?(record)
202
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
203
- end
204
- end
205
- origin_set_inverse_instance(record, instance)
206
- end
207
- end
208
-
209
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
210
- alias_method :origin_has_cached_counter?, :has_cached_counter?
211
-
212
- def has_cached_counter?
213
- result = origin_has_cached_counter?
214
- if Bullet.start? && !result
215
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
216
- end
217
- result
218
- end
219
- end
220
-
221
- ::ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
222
- alias_method :origin_has_cached_counter?, :has_cached_counter?
223
- def has_cached_counter?
224
- result = origin_has_cached_counter?
225
- if Bullet.start? && !result
226
- Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name)
227
- end
228
- result
229
- end
230
- end
231
- end
232
- end
233
- end
@@ -1,205 +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
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
13
- Bullet::Detector::CounterCache.add_possible_objects(result)
14
- elsif result.is_a? ::ActiveRecord::Base
15
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result)
16
- Bullet::Detector::CounterCache.add_impossible_object(result)
17
- end
18
- end
19
- result
20
- end
21
- end
22
- end
23
-
24
- ::ActiveRecord::Relation.class_eval do
25
- alias_method :origin_to_a, :to_a
26
- # if select a collection of objects, then these objects have possible to cause N+1 query.
27
- # if select only one object, then the only one object has impossible to cause N+1 query.
28
- def to_a
29
- records = origin_to_a
30
- if Bullet.start?
31
- if records.size > 1
32
- Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
33
- Bullet::Detector::CounterCache.add_possible_objects(records)
34
- elsif records.size == 1
35
- Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
36
- Bullet::Detector::CounterCache.add_impossible_object(records.first)
37
- end
38
- end
39
- records
40
- end
41
- end
42
-
43
- ::ActiveRecord::Persistence.class_eval do
44
- alias_method :origin_save, :save
45
- def save(*args, &proc)
46
- was_new_record = new_record?
47
- origin_save(*args, &proc).tap do |result|
48
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
49
- end
50
- end
51
-
52
- alias_method :origin_save!, :save!
53
- def save!(*args, &proc)
54
- was_new_record = new_record?
55
- origin_save!(*args, &proc).tap do |result|
56
- Bullet::Detector::NPlusOneQuery.add_impossible_object(self) if result && was_new_record
57
- end
58
- end
59
- end
60
-
61
- ::ActiveRecord::Associations::Preloader.class_eval do
62
- # include query for one to many associations.
63
- # keep this eager loadings.
64
- alias_method :origin_initialize, :initialize
65
- def initialize(records, associations, preload_scope = nil)
66
- origin_initialize(records, associations, preload_scope)
67
- if Bullet.start?
68
- records = [records].flatten.compact.uniq
69
- return if records.empty?
70
- records.each do |record|
71
- Bullet::Detector::Association.add_object_associations(record, associations)
72
- end
73
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
74
- end
75
- end
76
- end
77
-
78
- ::ActiveRecord::FinderMethods.class_eval do
79
- # add includes in scope
80
- alias_method :origin_find_with_associations, :find_with_associations
81
- def find_with_associations
82
- records = origin_find_with_associations
83
- if Bullet.start?
84
- associations = (eager_load_values + includes_values).uniq
85
- records.each do |record|
86
- Bullet::Detector::Association.add_object_associations(record, associations)
87
- end
88
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
89
- end
90
- records
91
- end
92
- end
93
-
94
- ::ActiveRecord::Associations::JoinDependency.class_eval do
95
- alias_method :origin_instantiate, :instantiate
96
- alias_method :origin_construct_association, :construct_association
97
-
98
- def instantiate(rows)
99
- @bullet_eager_loadings = {}
100
- records = origin_instantiate(rows)
101
-
102
- if Bullet.start?
103
- @bullet_eager_loadings.each do |klazz, eager_loadings_hash|
104
- objects = eager_loadings_hash.keys
105
- Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
106
- end
107
- end
108
- records
109
- end
110
-
111
- # call join associations
112
- def construct_association(record, join, row)
113
- result = origin_construct_association(record, join, row)
114
-
115
- if Bullet.start?
116
- associations = join.reflection.name
117
- Bullet::Detector::Association.add_object_associations(record, associations)
118
- Bullet::Detector::NPlusOneQuery.call_association(record, associations)
119
- @bullet_eager_loadings[record.class] ||= {}
120
- @bullet_eager_loadings[record.class][record] ||= Set.new
121
- @bullet_eager_loadings[record.class][record] << associations
122
- end
123
-
124
- result
125
- end
126
- end
127
-
128
- ::ActiveRecord::Associations::CollectionAssociation.class_eval do
129
- # call one to many associations
130
- alias_method :origin_load_target, :load_target
131
- def load_target
132
- if Bullet.start?
133
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
134
- end
135
- origin_load_target
136
- end
137
-
138
- alias_method :origin_include?, :include?
139
- def include?(object)
140
- if Bullet.start?
141
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
142
- end
143
- origin_include?(object)
144
- end
145
- end
146
-
147
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
148
- alias_method :origin_empty?, :empty?
149
- def empty?
150
- if Bullet.start? && !has_cached_counter?(@reflection)
151
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
152
- end
153
- origin_empty?
154
- end
155
- end
156
-
157
- ::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
158
- alias_method :origin_empty?, :empty?
159
- def empty?
160
- if Bullet.start?
161
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
162
- end
163
- origin_empty?
164
- end
165
- end
166
-
167
- ::ActiveRecord::Associations::SingularAssociation.class_eval do
168
- # call has_one and belongs_to associations
169
- alias_method :origin_reader, :reader
170
- def reader(force_reload = false)
171
- result = origin_reader(force_reload)
172
- if Bullet.start?
173
- Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
174
- Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
175
- end
176
- result
177
- end
178
- end
179
-
180
- ::ActiveRecord::Associations::Association.class_eval do
181
- alias_method :origin_set_inverse_instance, :set_inverse_instance
182
- def set_inverse_instance(record)
183
- if Bullet.start?
184
- if record && invertible_for?(record)
185
- Bullet::Detector::NPlusOneQuery.add_inversed_object(record, inverse_reflection_for(record).name)
186
- end
187
- end
188
- origin_set_inverse_instance(record)
189
- end
190
- end
191
-
192
- ::ActiveRecord::Associations::HasManyAssociation.class_eval do
193
- alias_method :origin_has_cached_counter?, :has_cached_counter?
194
-
195
- def has_cached_counter?(reflection = reflection())
196
- result = origin_has_cached_counter?(reflection)
197
- if Bullet.start? && !result
198
- Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name)
199
- end
200
- result
201
- end
202
- end
203
- end
204
- end
205
- end