bullet 5.1.0 → 5.1.1
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 +7 -2
- data/README.md +4 -2
- data/lib/bullet.rb +6 -1
- data/lib/bullet/active_record3.rb +15 -3
- data/lib/bullet/active_record3x.rb +15 -3
- data/lib/bullet/active_record4.rb +15 -3
- data/lib/bullet/active_record42.rb +3 -1
- data/lib/bullet/active_record5.rb +3 -1
- data/lib/bullet/version.rb +1 -1
- data/spec/integration/active_record3/association_spec.rb +11 -1
- data/spec/integration/active_record4/association_spec.rb +11 -1
- data/spec/integration/active_record5/association_spec.rb +11 -1
- data/spec/support/sqlite_seed.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0158f6af4990b365de2859cea97877e5b290ea83
|
4
|
+
data.tar.gz: cd8914938d74645ae75d01ee8feaf23e38f8d028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e92c13202832afaaf604072c06e695cfe552d5626318d6c625cebacdfdc13ecc14aeed8c64d6df483b4c05caa090ecee01e613228dae6466edbe66803e7333a
|
7
|
+
data.tar.gz: 7d365b32c075a00733e4c70daedcfbca042cb2334a77c6e132fc31b33e9dd23aaca8a65eaa1578ffba2f106303cf572e84e41b7fd6c7c61a239b2dbea9fcaabe
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Next Release
|
2
2
|
|
3
|
-
## 5.1.
|
3
|
+
## 5.1.1
|
4
|
+
|
5
|
+
* Fix `has_cached_counter?` is not defined in HABTM #297
|
6
|
+
* Fix false alert if preloaded association has no records #260
|
7
|
+
|
8
|
+
## 5.1.0 (05/21/2016)
|
4
9
|
|
5
10
|
* Fix false alert when `empty?` used with `counter_cache`
|
6
11
|
* Fix `alias_method_chain` deprecation for rails 5
|
@@ -8,7 +13,7 @@
|
|
8
13
|
* Fix false alert when querying immediately after creation
|
9
14
|
* Fix UnusedEagerLoading bug when multiple eager loading query include same objects
|
10
15
|
|
11
|
-
## 5.0.0 (01/06/
|
16
|
+
## 5.0.0 (01/06/2016)
|
12
17
|
|
13
18
|
* Support Rails 5.0.0.beta1
|
14
19
|
* Fix `has_many :through` infinite loop issue
|
data/README.md
CHANGED
@@ -238,7 +238,9 @@ Bullet outputs some details info, to enable debug mode, set
|
|
238
238
|
|
239
239
|
## Demo
|
240
240
|
|
241
|
-
Bullet is designed to function as you browse through your application in development. To see it in action,
|
241
|
+
Bullet is designed to function as you browse through your application in development. To see it in action,
|
242
|
+
you can visit [https://github.com/flyerhzm/bullet_test](https://github.com/flyerhzm/bullet_test) or
|
243
|
+
follow these steps to create, detect, and fix example query problems.
|
242
244
|
|
243
245
|
1\. Create an example application
|
244
246
|
|
@@ -458,4 +460,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
|
|
458
460
|
Post => [:comments]
|
459
461
|
```
|
460
462
|
|
461
|
-
Copyright (c) 2009 -
|
463
|
+
Copyright (c) 2009 - 2016 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
data/lib/bullet.rb
CHANGED
@@ -190,17 +190,22 @@ module Bullet
|
|
190
190
|
end
|
191
191
|
|
192
192
|
def profile
|
193
|
+
return_value = nil
|
193
194
|
if Bullet.enable?
|
194
195
|
begin
|
195
196
|
Bullet.start_request
|
196
197
|
|
197
|
-
yield
|
198
|
+
return_value = yield
|
198
199
|
|
199
200
|
Bullet.perform_out_of_channel_notifications if Bullet.notification?
|
200
201
|
ensure
|
201
202
|
Bullet.end_request
|
202
203
|
end
|
204
|
+
else
|
205
|
+
return_value = yield
|
203
206
|
end
|
207
|
+
|
208
|
+
return_value
|
204
209
|
end
|
205
210
|
|
206
211
|
private
|
@@ -134,6 +134,16 @@ module Bullet
|
|
134
134
|
origin_last(*args)
|
135
135
|
end
|
136
136
|
|
137
|
+
alias_method :origin_include?, :include?
|
138
|
+
def include?(object)
|
139
|
+
if Bullet.start?
|
140
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
141
|
+
end
|
142
|
+
origin_include?(object)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
137
147
|
alias_method :origin_empty?, :empty?
|
138
148
|
def empty?
|
139
149
|
if Bullet.start? && !has_cached_counter?
|
@@ -141,13 +151,15 @@ module Bullet
|
|
141
151
|
end
|
142
152
|
origin_empty?
|
143
153
|
end
|
154
|
+
end
|
144
155
|
|
145
|
-
|
146
|
-
|
156
|
+
::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
|
157
|
+
alias_method :origin_empty?, :empty?
|
158
|
+
def empty?
|
147
159
|
if Bullet.start?
|
148
160
|
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
149
161
|
end
|
150
|
-
|
162
|
+
origin_empty?
|
151
163
|
end
|
152
164
|
end
|
153
165
|
|
@@ -116,6 +116,16 @@ module Bullet
|
|
116
116
|
origin_load_target
|
117
117
|
end
|
118
118
|
|
119
|
+
alias_method :origin_include?, :include?
|
120
|
+
def include?(object)
|
121
|
+
if Bullet.start?
|
122
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
123
|
+
end
|
124
|
+
origin_include?(object)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
119
129
|
alias_method :origin_empty?, :empty?
|
120
130
|
def empty?
|
121
131
|
if Bullet.start? && !has_cached_counter?(@reflection)
|
@@ -123,13 +133,15 @@ module Bullet
|
|
123
133
|
end
|
124
134
|
origin_empty?
|
125
135
|
end
|
136
|
+
end
|
126
137
|
|
127
|
-
|
128
|
-
|
138
|
+
::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
|
139
|
+
alias_method :origin_empty?, :empty?
|
140
|
+
def empty?
|
129
141
|
if Bullet.start?
|
130
142
|
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
131
143
|
end
|
132
|
-
|
144
|
+
origin_empty?
|
133
145
|
end
|
134
146
|
end
|
135
147
|
|
@@ -116,6 +116,16 @@ module Bullet
|
|
116
116
|
origin_load_target
|
117
117
|
end
|
118
118
|
|
119
|
+
alias_method :origin_include?, :include?
|
120
|
+
def include?(object)
|
121
|
+
if Bullet.start?
|
122
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
123
|
+
end
|
124
|
+
origin_include?(object)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
::ActiveRecord::Associations::HasManyAssociation.class_eval do
|
119
129
|
alias_method :origin_empty?, :empty?
|
120
130
|
def empty?
|
121
131
|
if Bullet.start? && !has_cached_counter?(@reflection)
|
@@ -123,13 +133,15 @@ module Bullet
|
|
123
133
|
end
|
124
134
|
origin_empty?
|
125
135
|
end
|
136
|
+
end
|
126
137
|
|
127
|
-
|
128
|
-
|
138
|
+
::ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
|
139
|
+
alias_method :origin_empty?, :empty?
|
140
|
+
def empty?
|
129
141
|
if Bullet.start?
|
130
142
|
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name)
|
131
143
|
end
|
132
|
-
|
144
|
+
origin_empty?
|
133
145
|
end
|
134
146
|
end
|
135
147
|
|
@@ -135,7 +135,9 @@ module Bullet
|
|
135
135
|
records = origin_load_target
|
136
136
|
|
137
137
|
if Bullet.start?
|
138
|
-
|
138
|
+
if records.size > 1
|
139
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
|
140
|
+
end
|
139
141
|
if records.first.class.name !~ /^HABTM_/
|
140
142
|
if records.size > 1
|
141
143
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
@@ -143,7 +143,9 @@ module Bullet
|
|
143
143
|
records = origin_load_target
|
144
144
|
|
145
145
|
if Bullet.start?
|
146
|
-
|
146
|
+
if records.size > 1
|
147
|
+
Bullet::Detector::NPlusOneQuery.call_association(@owner, @reflection.name) unless @inversed
|
148
|
+
end
|
147
149
|
if records.first.class.name !~ /^HABTM_/
|
148
150
|
if records.size > 1
|
149
151
|
Bullet::Detector::NPlusOneQuery.add_possible_objects(records)
|
data/lib/bullet/version.rb
CHANGED
@@ -214,7 +214,7 @@ if !mongoid? && active_record3?
|
|
214
214
|
context "post => comment" do
|
215
215
|
it "should detect unused preload with post => comments" do
|
216
216
|
Post.includes(:comments).each do |post|
|
217
|
-
post.comments.first.name
|
217
|
+
post.comments.first.name if post.comments.first
|
218
218
|
end
|
219
219
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
220
220
|
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Post, :comments)
|
@@ -453,6 +453,16 @@ if !mongoid? && active_record3?
|
|
453
453
|
|
454
454
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
455
455
|
end
|
456
|
+
|
457
|
+
it "should detect non preload student => teachers with empty?" do
|
458
|
+
Student.all.each do |student|
|
459
|
+
student.teachers.empty?
|
460
|
+
end
|
461
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
462
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
463
|
+
|
464
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Student, :teachers)
|
465
|
+
end
|
456
466
|
end
|
457
467
|
end
|
458
468
|
|
@@ -214,7 +214,7 @@ if !mongoid? && active_record4?
|
|
214
214
|
context "post => comment" do
|
215
215
|
it "should detect unused preload with post => comments" do
|
216
216
|
Post.includes(:comments).each do |post|
|
217
|
-
post.comments.first.name
|
217
|
+
post.comments.first.name if post.comments.first
|
218
218
|
end
|
219
219
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
220
220
|
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Post, :comments)
|
@@ -465,6 +465,16 @@ if !mongoid? && active_record4?
|
|
465
465
|
|
466
466
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
467
467
|
end
|
468
|
+
|
469
|
+
it "should detect non preload student => teachers with empty?" do
|
470
|
+
Student.all.each do |student|
|
471
|
+
student.teachers.empty?
|
472
|
+
end
|
473
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
474
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
475
|
+
|
476
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Student, :teachers)
|
477
|
+
end
|
468
478
|
end
|
469
479
|
end
|
470
480
|
|
@@ -214,7 +214,7 @@ if !mongoid? && active_record5?
|
|
214
214
|
context "post => comment" do
|
215
215
|
it "should detect unused preload with post => comments" do
|
216
216
|
Post.includes(:comments).each do |post|
|
217
|
-
post.comments.first.name
|
217
|
+
post.comments.first.name if post.comments.first
|
218
218
|
end
|
219
219
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
220
220
|
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Post, :comments)
|
@@ -465,6 +465,16 @@ if !mongoid? && active_record5?
|
|
465
465
|
|
466
466
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
467
467
|
end
|
468
|
+
|
469
|
+
it "should detect non preload student => teachers with empty?" do
|
470
|
+
Student.all.each do |student|
|
471
|
+
student.teachers.empty?
|
472
|
+
end
|
473
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
474
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
475
|
+
|
476
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Student, :teachers)
|
477
|
+
end
|
468
478
|
end
|
469
479
|
end
|
470
480
|
|
data/spec/support/sqlite_seed.rb
CHANGED
@@ -16,6 +16,7 @@ module Support
|
|
16
16
|
post1 = category1.posts.create(:name => 'first', :writer => writer1)
|
17
17
|
post1a = category1.posts.create(:name => 'like first', :writer => writer2, active: false)
|
18
18
|
post2 = category2.posts.create(:name => 'second', :writer => writer2)
|
19
|
+
post3 = category2.posts.create(:name => 'third', :writer => writer2)
|
19
20
|
|
20
21
|
comment1 = post1.comments.create(:name => 'first', :author => writer1)
|
21
22
|
comment2 = post1.comments.create(:name => 'first2', :author => writer1)
|
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.1.
|
4
|
+
version: 5.1.1
|
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-
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|