bullet 8.1.3 → 8.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +19 -6
- data/lib/bullet/active_record70.rb +14 -0
- data/lib/bullet/active_record71.rb +14 -0
- data/lib/bullet/active_record72.rb +14 -0
- data/lib/bullet/active_record80.rb +14 -0
- data/lib/bullet/active_record81.rb +14 -0
- data/lib/bullet/{active_record60.rb → active_record82.rb} +74 -49
- data/lib/bullet/dependency.rb +10 -58
- data/lib/bullet/detector/association.rb +2 -2
- data/lib/bullet/detector/n_plus_one_query.rb +1 -1
- data/lib/bullet/rack.rb +35 -2
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +25 -0
- metadata +30 -8
- data/lib/bullet/active_record4.rb +0 -197
- data/lib/bullet/active_record41.rb +0 -191
- data/lib/bullet/active_record42.rb +0 -262
- data/lib/bullet/active_record5.rb +0 -294
- data/lib/bullet/active_record52.rb +0 -278
- data/lib/bullet/active_record61.rb +0 -310
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bullet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.
|
|
4
|
+
version: 8.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Huang
|
|
@@ -37,6 +37,34 @@ dependencies:
|
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: '1.11'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: ostruct
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: logger
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
40
68
|
description: help to kill N+1 queries and unused eager loading.
|
|
41
69
|
email:
|
|
42
70
|
- flyerhzm@gmail.com
|
|
@@ -49,18 +77,12 @@ files:
|
|
|
49
77
|
- README.md
|
|
50
78
|
- lib/bullet.rb
|
|
51
79
|
- lib/bullet/active_job.rb
|
|
52
|
-
- lib/bullet/active_record4.rb
|
|
53
|
-
- lib/bullet/active_record41.rb
|
|
54
|
-
- lib/bullet/active_record42.rb
|
|
55
|
-
- lib/bullet/active_record5.rb
|
|
56
|
-
- lib/bullet/active_record52.rb
|
|
57
|
-
- lib/bullet/active_record60.rb
|
|
58
|
-
- lib/bullet/active_record61.rb
|
|
59
80
|
- lib/bullet/active_record70.rb
|
|
60
81
|
- lib/bullet/active_record71.rb
|
|
61
82
|
- lib/bullet/active_record72.rb
|
|
62
83
|
- lib/bullet/active_record80.rb
|
|
63
84
|
- lib/bullet/active_record81.rb
|
|
85
|
+
- lib/bullet/active_record82.rb
|
|
64
86
|
- lib/bullet/bullet_xhr.js
|
|
65
87
|
- lib/bullet/dependency.rb
|
|
66
88
|
- lib/bullet/detector.rb
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Bullet
|
|
4
|
-
module ActiveRecord
|
|
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, binds = [])
|
|
11
|
-
result = origin_find_by_sql(sql, binds)
|
|
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
|
-
def _create_record_with_bullet(*args)
|
|
52
|
-
_create_record_without_bullet(*args).tap do
|
|
53
|
-
Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
|
|
54
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
alias_method_chain :_create_record, :bullet
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
::ActiveRecord::Associations::Preloader.class_eval do
|
|
61
|
-
# include query for one to many associations.
|
|
62
|
-
# keep this eager loadings.
|
|
63
|
-
alias_method :origin_initialize, :initialize
|
|
64
|
-
def initialize(records, associations, preload_scope = nil)
|
|
65
|
-
origin_initialize(records, associations, preload_scope)
|
|
66
|
-
|
|
67
|
-
if Bullet.start?
|
|
68
|
-
records = [records].flatten.compact.uniq
|
|
69
|
-
return if records.empty?
|
|
70
|
-
|
|
71
|
-
records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
|
|
72
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
::ActiveRecord::FinderMethods.class_eval do
|
|
78
|
-
# add includes in scope
|
|
79
|
-
alias_method :origin_find_with_associations, :find_with_associations
|
|
80
|
-
def find_with_associations
|
|
81
|
-
records = origin_find_with_associations
|
|
82
|
-
if Bullet.start?
|
|
83
|
-
associations = (eager_load_values + includes_values).uniq
|
|
84
|
-
records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
|
|
85
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
|
86
|
-
end
|
|
87
|
-
records
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
::ActiveRecord::Associations::JoinDependency.class_eval do
|
|
92
|
-
alias_method :origin_instantiate, :instantiate
|
|
93
|
-
alias_method :origin_construct_association, :construct_association
|
|
94
|
-
|
|
95
|
-
def instantiate(rows)
|
|
96
|
-
@bullet_eager_loadings = {}
|
|
97
|
-
records = origin_instantiate(rows)
|
|
98
|
-
|
|
99
|
-
if Bullet.start?
|
|
100
|
-
@bullet_eager_loadings.each do |_klazz, eager_loadings_hash|
|
|
101
|
-
objects = eager_loadings_hash.keys
|
|
102
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
records
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# call join associations
|
|
109
|
-
def construct_association(record, join, row)
|
|
110
|
-
result = origin_construct_association(record, join, row)
|
|
111
|
-
|
|
112
|
-
if Bullet.start?
|
|
113
|
-
associations = [join.reflection.name]
|
|
114
|
-
if join.reflection.nested?
|
|
115
|
-
associations << join.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
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
result
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
::ActiveRecord::Associations::CollectionAssociation.class_eval do
|
|
131
|
-
# call one to many associations
|
|
132
|
-
alias_method :origin_load_target, :load_target
|
|
133
|
-
def load_target
|
|
134
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
|
|
135
|
-
origin_load_target
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
alias_method :origin_include?, :include?
|
|
139
|
-
def include?(object)
|
|
140
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
|
|
141
|
-
origin_include?(object)
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
146
|
-
alias_method :origin_empty?, :empty?
|
|
147
|
-
def empty?
|
|
148
|
-
if Bullet.start? && !loaded? && !has_cached_counter?(@reflection)
|
|
149
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
150
|
-
end
|
|
151
|
-
origin_empty?
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
|
|
156
|
-
alias_method :origin_empty?, :empty?
|
|
157
|
-
def empty?
|
|
158
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start? && !loaded?
|
|
159
|
-
origin_empty?
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
::ActiveRecord::Associations::SingularAssociation.class_eval do
|
|
164
|
-
# call has_one and belongs_to associations
|
|
165
|
-
alias_method :origin_reader, :reader
|
|
166
|
-
def reader(force_reload = false)
|
|
167
|
-
result = origin_reader(force_reload)
|
|
168
|
-
if Bullet.start?
|
|
169
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name, inversed: @inversed)
|
|
170
|
-
Bullet::Detector::NPlusOneQuery.add_possible_objects(result) unless @inversed
|
|
171
|
-
end
|
|
172
|
-
result
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
177
|
-
alias_method :origin_has_cached_counter?, :has_cached_counter?
|
|
178
|
-
|
|
179
|
-
def has_cached_counter?(reflection = reflection())
|
|
180
|
-
result = origin_has_cached_counter?(reflection)
|
|
181
|
-
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) if Bullet.start? && !result
|
|
182
|
-
result
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
::ActiveRecord::Associations::CollectionProxy.class_eval do
|
|
187
|
-
def count(column_name = nil, options = {})
|
|
188
|
-
if Bullet.start?
|
|
189
|
-
Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
|
|
190
|
-
Bullet::Detector::NPlusOneQuery.call_association(proxy_association.owner, proxy_association.reflection.name)
|
|
191
|
-
end
|
|
192
|
-
super(column_name, options)
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Bullet
|
|
4
|
-
module ActiveRecord
|
|
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, binds = [])
|
|
11
|
-
result = origin_find_by_sql(sql, binds)
|
|
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
|
-
|
|
34
|
-
# if select a collection of objects, then these objects have possible to cause N+1 query.
|
|
35
|
-
# if select only one object, then the only one object has impossible to cause N+1 query.
|
|
36
|
-
def to_a
|
|
37
|
-
records = origin_to_a
|
|
38
|
-
if Bullet.start?
|
|
39
|
-
if records.first.class.name !~ /^HABTM_/
|
|
40
|
-
if records.size > 1
|
|
41
|
-
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
|
42
|
-
Bullet::Detector::CounterCache.add_possible_objects(records)
|
|
43
|
-
elsif records.size == 1
|
|
44
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
|
|
45
|
-
Bullet::Detector::CounterCache.add_impossible_object(records.first)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
records
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
::ActiveRecord::Persistence.class_eval do
|
|
54
|
-
def _create_record_with_bullet(*args)
|
|
55
|
-
_create_record_without_bullet(*args).tap do
|
|
56
|
-
Bullet::Detector::NPlusOneQuery.update_inversed_object(self)
|
|
57
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(self)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
alias_method_chain :_create_record, :bullet
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
::ActiveRecord::Associations::Preloader.class_eval do
|
|
64
|
-
alias_method :origin_preloaders_on, :preloaders_on
|
|
65
|
-
|
|
66
|
-
def preloaders_on(association, records, scope)
|
|
67
|
-
if Bullet.start?
|
|
68
|
-
records.compact!
|
|
69
|
-
if records.first.class.name !~ /^HABTM_/
|
|
70
|
-
records.each { |record| Bullet::Detector::Association.add_object_associations(record, association) }
|
|
71
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, association)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
origin_preloaders_on(association, records, scope)
|
|
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
|
-
return origin_find_with_associations { |r| yield r } if block_given?
|
|
83
|
-
|
|
84
|
-
records = origin_find_with_associations
|
|
85
|
-
if Bullet.start?
|
|
86
|
-
associations = (eager_load_values + includes_values).uniq
|
|
87
|
-
records.each { |record| Bullet::Detector::Association.add_object_associations(record, associations) }
|
|
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_model, :construct_model
|
|
97
|
-
|
|
98
|
-
def instantiate(result_set, aliases)
|
|
99
|
-
@bullet_eager_loadings = {}
|
|
100
|
-
records = origin_instantiate(result_set, aliases)
|
|
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_model(record, node, row, model_cache, id, aliases)
|
|
113
|
-
result = origin_construct_model(record, node, row, model_cache, id, aliases)
|
|
114
|
-
|
|
115
|
-
if Bullet.start?
|
|
116
|
-
associations = [node.reflection.name]
|
|
117
|
-
if node.reflection.nested?
|
|
118
|
-
associations << node.reflection.through_reflection.name
|
|
119
|
-
end
|
|
120
|
-
associations.each do |association|
|
|
121
|
-
Bullet::Detector::Association.add_object_associations(record, association)
|
|
122
|
-
Bullet::Detector::NPlusOneQuery.call_association(record, association)
|
|
123
|
-
@bullet_eager_loadings[record.class] ||= {}
|
|
124
|
-
@bullet_eager_loadings[record.class][record] ||= Set.new
|
|
125
|
-
@bullet_eager_loadings[record.class][record] << association
|
|
126
|
-
end
|
|
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
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name, inversed: @inversed) if Bullet.start?
|
|
138
|
-
origin_load_target
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
alias_method :origin_empty?, :empty?
|
|
142
|
-
def empty?
|
|
143
|
-
if Bullet.start? && !has_cached_counter?(@reflection)
|
|
144
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
|
145
|
-
end
|
|
146
|
-
origin_empty?
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
alias_method :origin_include?, :include?
|
|
150
|
-
def include?(object)
|
|
151
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) if Bullet.start?
|
|
152
|
-
origin_include?(object)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
::ActiveRecord::Associations::SingularAssociation.class_eval do
|
|
157
|
-
# call has_one and belongs_to associations
|
|
158
|
-
alias_method :origin_reader, :reader
|
|
159
|
-
def reader(force_reload = false)
|
|
160
|
-
result = origin_reader(force_reload)
|
|
161
|
-
if Bullet.start?
|
|
162
|
-
if @owner.class.name !~ /^HABTM_/
|
|
163
|
-
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name, inversed: @inversed)
|
|
164
|
-
Bullet::Detector::NPlusOneQuery.add_possible_objects(result) unless @inversed
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
result
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
|
172
|
-
alias_method :origin_count_records, :count_records
|
|
173
|
-
def count_records
|
|
174
|
-
result = has_cached_counter?
|
|
175
|
-
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) if Bullet.start? && !result
|
|
176
|
-
origin_count_records
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
::ActiveRecord::Associations::CollectionProxy.class_eval do
|
|
181
|
-
def count(column_name = nil, options = {})
|
|
182
|
-
if Bullet.start?
|
|
183
|
-
Bullet::Detector::CounterCache.add_counter_cache(proxy_association.owner, proxy_association.reflection.name)
|
|
184
|
-
Bullet::Detector::NPlusOneQuery.call_association(proxy_association.owner, proxy_association.reflection.name)
|
|
185
|
-
end
|
|
186
|
-
super(column_name, options)
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
end
|