bullet_instructure 4.0.5 → 4.14.7
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/.travis.yml +27 -1
- data/CHANGELOG.md +44 -2
- data/Gemfile.mongoid +0 -2
- data/Gemfile.mongoid-2.4 +2 -4
- data/Gemfile.mongoid-2.5 +2 -4
- data/Gemfile.mongoid-2.6 +1 -3
- data/Gemfile.mongoid-2.7 +2 -4
- data/Gemfile.mongoid-2.8 +2 -4
- data/Gemfile.mongoid-3.0 +2 -4
- data/Gemfile.mongoid-3.1 +2 -4
- data/Gemfile.mongoid-4.0 +2 -4
- data/Gemfile.rails-3.0 +1 -3
- data/Gemfile.rails-3.1 +1 -3
- data/Gemfile.rails-3.2 +1 -3
- data/Gemfile.rails-4.0 +1 -3
- data/Gemfile.rails-4.1 +1 -3
- data/Gemfile.rails-4.2 +17 -0
- data/README.md +55 -43
- data/bullet_instructure.gemspec +2 -1
- data/lib/bullet/active_record3.rb +68 -34
- data/lib/bullet/active_record3x.rb +60 -32
- data/lib/bullet/active_record4.rb +57 -39
- data/lib/bullet/active_record41.rb +83 -42
- data/lib/bullet/active_record42.rb +195 -0
- data/lib/bullet/dependency.rb +6 -0
- data/lib/bullet/detector/association.rb +23 -17
- data/lib/bullet/detector/counter_cache.rb +16 -16
- data/lib/bullet/detector/n_plus_one_query.rb +43 -30
- data/lib/bullet/detector/unused_eager_loading.rb +2 -2
- data/lib/bullet/ext/object.rb +6 -2
- data/lib/bullet/notification/base.rb +17 -18
- data/lib/bullet/notification/n_plus_one_query.rb +6 -4
- data/lib/bullet/notification/unused_eager_loading.rb +1 -1
- data/lib/bullet/rack.rb +21 -14
- data/lib/bullet/version.rb +2 -2
- data/lib/bullet.rb +18 -10
- data/spec/bullet/detector/counter_cache_spec.rb +8 -8
- data/spec/bullet/detector/n_plus_one_query_spec.rb +27 -27
- data/spec/bullet/ext/object_spec.rb +14 -0
- data/spec/bullet/notification/base_spec.rb +30 -18
- data/spec/bullet/notification/n_plus_one_query_spec.rb +3 -3
- data/spec/bullet/notification/unused_eager_loading_spec.rb +1 -1
- data/spec/bullet/rack_spec.rb +3 -3
- data/spec/bullet_spec.rb +2 -2
- data/spec/integration/active_record3/association_spec.rb +22 -2
- data/spec/integration/active_record4/association_spec.rb +47 -2
- data/spec/models/category.rb +5 -2
- data/spec/models/comment.rb +2 -0
- data/spec/models/post.rb +8 -3
- data/spec/models/reply.rb +3 -0
- data/spec/models/submission.rb +1 -1
- data/spec/spec_helper.rb +4 -4
- data/spec/support/sqlite_seed.rb +14 -6
- data/test.sh +1 -0
- data/update.sh +14 -0
- metadata +26 -9
- data/.ruby-version +0 -1
data/bullet_instructure.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.required_rubygems_version = ">= 1.3.6"
|
19
19
|
|
20
20
|
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
21
|
-
s.add_runtime_dependency "uniform_notifier", "
|
21
|
+
s.add_runtime_dependency "uniform_notifier", "~> 1.9.0"
|
22
|
+
s.add_runtime_dependency "redcarpet", "3.0.0"
|
22
23
|
|
23
24
|
s.files = `git ls-files`.split("\n")
|
24
25
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -8,12 +8,14 @@ module Bullet
|
|
8
8
|
# if select only one object, then the only one object has impossible to cause N+1 query.
|
9
9
|
def to_a
|
10
10
|
records = origin_to_a
|
11
|
-
if
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
if Bullet.start?
|
12
|
+
if records.size > 1
|
13
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
14
|
+
Bullet::Detector::CounterCache.add_possible_objects(records)
|
15
|
+
elsif records.size == 1
|
16
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
|
17
|
+
Bullet::Detector::CounterCache.add_impossible_object(records.first)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
records
|
19
21
|
end
|
@@ -24,12 +26,14 @@ module Bullet
|
|
24
26
|
# include query for one to many associations.
|
25
27
|
# keep this eager loadings.
|
26
28
|
def preload_associations(records, associations, preload_options={})
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
if Bullet.start?
|
30
|
+
records = [records].flatten.compact.uniq
|
31
|
+
return if records.empty?
|
32
|
+
records.each do |record|
|
33
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
34
|
+
end
|
35
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
31
36
|
end
|
32
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
33
37
|
origin_preload_associations(records, associations, preload_options={})
|
34
38
|
end
|
35
39
|
end
|
@@ -39,11 +43,13 @@ module Bullet
|
|
39
43
|
alias_method :origin_find_with_associations, :find_with_associations
|
40
44
|
def find_with_associations
|
41
45
|
records = origin_find_with_associations
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
if Bullet.start?
|
47
|
+
associations = (@eager_load_values + @includes_values).uniq
|
48
|
+
records.each do |record|
|
49
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
50
|
+
end
|
51
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
45
52
|
end
|
46
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
47
53
|
records
|
48
54
|
end
|
49
55
|
end
|
@@ -56,9 +62,11 @@ module Bullet
|
|
56
62
|
@bullet_eager_loadings = {}
|
57
63
|
records = origin_instantiate(rows)
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
if Bullet.start?
|
66
|
+
@bullet_eager_loadings.each do |klazz, eager_loadings_hash|
|
67
|
+
objects = eager_loadings_hash.keys
|
68
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
|
69
|
+
end
|
62
70
|
end
|
63
71
|
records
|
64
72
|
end
|
@@ -67,12 +75,14 @@ module Bullet
|
|
67
75
|
def construct_association(record, join, row)
|
68
76
|
result = origin_construct_association(record, join, row)
|
69
77
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
if Bullet.start?
|
79
|
+
associations = join.reflection.name
|
80
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
81
|
+
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
82
|
+
@bullet_eager_loadings[record.class] ||= {}
|
83
|
+
@bullet_eager_loadings[record.class][record] ||= Set.new
|
84
|
+
@bullet_eager_loadings[record.class][record] << associations
|
85
|
+
end
|
76
86
|
|
77
87
|
result
|
78
88
|
end
|
@@ -82,27 +92,43 @@ module Bullet
|
|
82
92
|
# call one to many associations
|
83
93
|
alias_method :origin_load_target, :load_target
|
84
94
|
def load_target
|
85
|
-
Bullet
|
95
|
+
if Bullet.start?
|
96
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
97
|
+
end
|
86
98
|
origin_load_target
|
87
99
|
end
|
88
100
|
|
89
101
|
alias_method :origin_first, :first
|
90
102
|
def first(*args)
|
91
|
-
Bullet
|
103
|
+
if Bullet.start?
|
104
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
105
|
+
end
|
92
106
|
origin_first(*args)
|
93
107
|
end
|
94
108
|
|
95
109
|
alias_method :origin_last, :last
|
96
110
|
def last(*args)
|
97
|
-
Bullet
|
111
|
+
if Bullet.start?
|
112
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
113
|
+
end
|
98
114
|
origin_last(*args)
|
99
115
|
end
|
100
116
|
|
101
117
|
alias_method :origin_empty?, :empty?
|
102
118
|
def empty?
|
103
|
-
Bullet
|
119
|
+
if Bullet.start?
|
120
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
121
|
+
end
|
104
122
|
origin_empty?
|
105
123
|
end
|
124
|
+
|
125
|
+
alias_method :origin_include?, :include?
|
126
|
+
def include?(object)
|
127
|
+
if Bullet.start?
|
128
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
129
|
+
end
|
130
|
+
origin_include?(object)
|
131
|
+
end
|
106
132
|
end
|
107
133
|
|
108
134
|
::ActiveRecord::Associations::AssociationProxy.class_eval do
|
@@ -111,15 +137,19 @@ module Bullet
|
|
111
137
|
def load_target
|
112
138
|
# avoid stack level too deep
|
113
139
|
result = origin_load_target
|
114
|
-
Bullet
|
115
|
-
|
140
|
+
if Bullet.start?
|
141
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless caller.any? { |c| c.include?("load_target") }
|
142
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
143
|
+
end
|
116
144
|
result
|
117
145
|
end
|
118
146
|
|
119
147
|
alias_method :origin_set_inverse_instance, :set_inverse_instance
|
120
148
|
def set_inverse_instance(record, instance)
|
121
|
-
if
|
122
|
-
|
149
|
+
if Bullet.start?
|
150
|
+
if record && we_can_set_the_inverse_on_this?(record)
|
151
|
+
Bullet::Detector::NPlusOneQuery.add_inversed_object(record, @reflection.inverse_of.name)
|
152
|
+
end
|
123
153
|
end
|
124
154
|
origin_set_inverse_instance(record, instance)
|
125
155
|
end
|
@@ -130,7 +160,9 @@ module Bullet
|
|
130
160
|
|
131
161
|
def has_cached_counter?
|
132
162
|
result = origin_has_cached_counter?
|
133
|
-
Bullet
|
163
|
+
if Bullet.start?
|
164
|
+
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
|
165
|
+
end
|
134
166
|
result
|
135
167
|
end
|
136
168
|
end
|
@@ -139,7 +171,9 @@ module Bullet
|
|
139
171
|
alias_method :origin_has_cached_counter?, :has_cached_counter?
|
140
172
|
def has_cached_counter?
|
141
173
|
result = origin_has_cached_counter?
|
142
|
-
Bullet
|
174
|
+
if Bullet.start?
|
175
|
+
Bullet::Detector::CounterCache.add_counter_cache(@owner, @reflection.name) unless result
|
176
|
+
end
|
143
177
|
result
|
144
178
|
end
|
145
179
|
end
|
@@ -8,12 +8,14 @@ module Bullet
|
|
8
8
|
# if select only one object, then the only one object has impossible to cause N+1 query.
|
9
9
|
def to_a
|
10
10
|
records = origin_to_a
|
11
|
-
if
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
if Bullet.start?
|
12
|
+
if records.size > 1
|
13
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
14
|
+
Bullet::Detector::CounterCache.add_possible_objects(records)
|
15
|
+
elsif records.size == 1
|
16
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
|
17
|
+
Bullet::Detector::CounterCache.add_impossible_object(records.first)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
records
|
19
21
|
end
|
@@ -25,12 +27,14 @@ module Bullet
|
|
25
27
|
alias_method :origin_initialize, :initialize
|
26
28
|
def initialize(records, associations, preload_scope = nil)
|
27
29
|
origin_initialize(records, associations, preload_scope)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
if Bullet.start?
|
31
|
+
records = [records].flatten.compact.uniq
|
32
|
+
return if records.empty?
|
33
|
+
records.each do |record|
|
34
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
35
|
+
end
|
36
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
32
37
|
end
|
33
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
@@ -39,11 +43,13 @@ module Bullet
|
|
39
43
|
alias_method :origin_find_with_associations, :find_with_associations
|
40
44
|
def find_with_associations
|
41
45
|
records = origin_find_with_associations
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
if Bullet.start?
|
47
|
+
associations = (eager_load_values + includes_values).uniq
|
48
|
+
records.each do |record|
|
49
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
50
|
+
end
|
51
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
45
52
|
end
|
46
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
47
53
|
records
|
48
54
|
end
|
49
55
|
end
|
@@ -56,9 +62,11 @@ module Bullet
|
|
56
62
|
@bullet_eager_loadings = {}
|
57
63
|
records = origin_instantiate(rows)
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
if Bullet.start?
|
66
|
+
@bullet_eager_loadings.each do |klazz, eager_loadings_hash|
|
67
|
+
objects = eager_loadings_hash.keys
|
68
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
|
69
|
+
end
|
62
70
|
end
|
63
71
|
records
|
64
72
|
end
|
@@ -67,12 +75,14 @@ module Bullet
|
|
67
75
|
def construct_association(record, join, row)
|
68
76
|
result = origin_construct_association(record, join, row)
|
69
77
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
if Bullet.start?
|
79
|
+
associations = join.reflection.name
|
80
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
81
|
+
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
82
|
+
@bullet_eager_loadings[record.class] ||= {}
|
83
|
+
@bullet_eager_loadings[record.class][record] ||= Set.new
|
84
|
+
@bullet_eager_loadings[record.class][record] << associations
|
85
|
+
end
|
76
86
|
|
77
87
|
result
|
78
88
|
end
|
@@ -82,15 +92,27 @@ module Bullet
|
|
82
92
|
# call one to many associations
|
83
93
|
alias_method :origin_load_target, :load_target
|
84
94
|
def load_target
|
85
|
-
Bullet
|
95
|
+
if Bullet.start?
|
96
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
97
|
+
end
|
86
98
|
origin_load_target
|
87
99
|
end
|
88
100
|
|
89
101
|
alias_method :origin_empty?, :empty?
|
90
102
|
def empty?
|
91
|
-
Bullet
|
103
|
+
if Bullet.start?
|
104
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
105
|
+
end
|
92
106
|
origin_empty?
|
93
107
|
end
|
108
|
+
|
109
|
+
alias_method :origin_include?, :include?
|
110
|
+
def include?(object)
|
111
|
+
if Bullet.start?
|
112
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
113
|
+
end
|
114
|
+
origin_include?(object)
|
115
|
+
end
|
94
116
|
end
|
95
117
|
|
96
118
|
::ActiveRecord::Associations::SingularAssociation.class_eval do
|
@@ -98,8 +120,10 @@ module Bullet
|
|
98
120
|
alias_method :origin_reader, :reader
|
99
121
|
def reader(force_reload = false)
|
100
122
|
result = origin_reader(force_reload)
|
101
|
-
Bullet
|
102
|
-
|
123
|
+
if Bullet.start?
|
124
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
125
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
126
|
+
end
|
103
127
|
result
|
104
128
|
end
|
105
129
|
end
|
@@ -107,8 +131,10 @@ module Bullet
|
|
107
131
|
::ActiveRecord::Associations::Association.class_eval do
|
108
132
|
alias_method :origin_set_inverse_instance, :set_inverse_instance
|
109
133
|
def set_inverse_instance(record)
|
110
|
-
if
|
111
|
-
|
134
|
+
if Bullet.start?
|
135
|
+
if record && invertible_for?(record)
|
136
|
+
Bullet::Detector::NPlusOneQuery.add_inversed_object(record, inverse_reflection_for(record).name)
|
137
|
+
end
|
112
138
|
end
|
113
139
|
origin_set_inverse_instance(record)
|
114
140
|
end
|
@@ -117,9 +143,11 @@ module Bullet
|
|
117
143
|
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
118
144
|
alias_method :origin_has_cached_counter?, :has_cached_counter?
|
119
145
|
|
120
|
-
def has_cached_counter?(reflection = reflection
|
146
|
+
def has_cached_counter?(reflection = reflection)
|
121
147
|
result = origin_has_cached_counter?(reflection)
|
122
|
-
Bullet
|
148
|
+
if Bullet.start?
|
149
|
+
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
|
150
|
+
end
|
123
151
|
result
|
124
152
|
end
|
125
153
|
end
|
@@ -8,12 +8,14 @@ module Bullet
|
|
8
8
|
# if select only one object, then the only one object has impossible to cause N+1 query.
|
9
9
|
def to_a
|
10
10
|
records = origin_to_a
|
11
|
-
if
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
if Bullet.start?
|
12
|
+
if records.size > 1
|
13
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
14
|
+
Bullet::Detector::CounterCache.add_possible_objects(records)
|
15
|
+
elsif records.size == 1
|
16
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(records.first)
|
17
|
+
Bullet::Detector::CounterCache.add_impossible_object(records.first)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
records
|
19
21
|
end
|
@@ -25,12 +27,14 @@ module Bullet
|
|
25
27
|
alias_method :origin_initialize, :initialize
|
26
28
|
def initialize(records, associations, preload_scope = nil)
|
27
29
|
origin_initialize(records, associations, preload_scope)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
if Bullet.start?
|
31
|
+
records = [records].flatten.compact.uniq
|
32
|
+
return if records.empty?
|
33
|
+
records.each do |record|
|
34
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
35
|
+
end
|
36
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
32
37
|
end
|
33
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
@@ -39,11 +43,13 @@ module Bullet
|
|
39
43
|
alias_method :origin_find_with_associations, :find_with_associations
|
40
44
|
def find_with_associations
|
41
45
|
records = origin_find_with_associations
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
if Bullet.start?
|
47
|
+
associations = (eager_load_values + includes_values).uniq
|
48
|
+
records.each do |record|
|
49
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
50
|
+
end
|
51
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
45
52
|
end
|
46
|
-
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(records, associations)
|
47
53
|
records
|
48
54
|
end
|
49
55
|
end
|
@@ -56,9 +62,11 @@ module Bullet
|
|
56
62
|
@bullet_eager_loadings = {}
|
57
63
|
records = origin_instantiate(rows)
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
if Bullet.start?
|
66
|
+
@bullet_eager_loadings.each do |klazz, eager_loadings_hash|
|
67
|
+
objects = eager_loadings_hash.keys
|
68
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(objects, eager_loadings_hash[objects.first].to_a)
|
69
|
+
end
|
62
70
|
end
|
63
71
|
records
|
64
72
|
end
|
@@ -67,12 +75,14 @@ module Bullet
|
|
67
75
|
def construct_association(record, join, row)
|
68
76
|
result = origin_construct_association(record, join, row)
|
69
77
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
if Bullet.start?
|
79
|
+
associations = join.reflection.name
|
80
|
+
Bullet::Detector::Association.add_object_associations(record, associations)
|
81
|
+
Bullet::Detector::NPlusOneQuery.call_association(record, associations)
|
82
|
+
@bullet_eager_loadings[record.class] ||= {}
|
83
|
+
@bullet_eager_loadings[record.class][record] ||= Set.new
|
84
|
+
@bullet_eager_loadings[record.class][record] << associations
|
85
|
+
end
|
76
86
|
|
77
87
|
result
|
78
88
|
end
|
@@ -82,15 +92,27 @@ module Bullet
|
|
82
92
|
# call one to many associations
|
83
93
|
alias_method :origin_load_target, :load_target
|
84
94
|
def load_target
|
85
|
-
Bullet
|
95
|
+
if Bullet.start?
|
96
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
97
|
+
end
|
86
98
|
origin_load_target
|
87
99
|
end
|
88
100
|
|
89
101
|
alias_method :origin_empty?, :empty?
|
90
102
|
def empty?
|
91
|
-
Bullet
|
103
|
+
if Bullet.start?
|
104
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
105
|
+
end
|
92
106
|
origin_empty?
|
93
107
|
end
|
108
|
+
|
109
|
+
alias_method :origin_include?, :include?
|
110
|
+
def include?(object)
|
111
|
+
if Bullet.start?
|
112
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
113
|
+
end
|
114
|
+
origin_include?(object)
|
115
|
+
end
|
94
116
|
end
|
95
117
|
|
96
118
|
::ActiveRecord::Associations::SingularAssociation.class_eval do
|
@@ -98,19 +120,13 @@ module Bullet
|
|
98
120
|
alias_method :origin_reader, :reader
|
99
121
|
def reader(force_reload = false)
|
100
122
|
result = origin_reader(force_reload)
|
101
|
-
Bullet
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
::ActiveRecord::Associations::Association.class_eval do
|
108
|
-
alias_method :origin_set_inverse_instance, :set_inverse_instance
|
109
|
-
def set_inverse_instance(record)
|
110
|
-
if record && invertible_for?(record)
|
111
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(record)
|
123
|
+
if Bullet.start?
|
124
|
+
unless @inversed
|
125
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
126
|
+
Bullet::Detector::NPlusOneQuery.add_possible_objects(result)
|
127
|
+
end
|
112
128
|
end
|
113
|
-
|
129
|
+
result
|
114
130
|
end
|
115
131
|
end
|
116
132
|
|
@@ -119,7 +135,9 @@ module Bullet
|
|
119
135
|
|
120
136
|
def has_cached_counter?(reflection = reflection())
|
121
137
|
result = origin_has_cached_counter?(reflection)
|
122
|
-
Bullet
|
138
|
+
if Bullet.start?
|
139
|
+
Bullet::Detector::CounterCache.add_counter_cache(owner, reflection.name) unless result
|
140
|
+
end
|
123
141
|
result
|
124
142
|
end
|
125
143
|
end
|