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
@@ -39,7 +39,7 @@ if !mongoid? && active_record3?
|
|
39
39
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
40
40
|
end
|
41
41
|
|
42
|
-
it "should detect non preload comment => post with inverse_of" do
|
42
|
+
it "should not detect non preload comment => post with inverse_of" do
|
43
43
|
Post.includes(:comments).each do |post|
|
44
44
|
post.comments.each do |comment|
|
45
45
|
comment.name
|
@@ -61,6 +61,17 @@ if !mongoid? && active_record3?
|
|
61
61
|
|
62
62
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
63
63
|
end
|
64
|
+
|
65
|
+
it "should detect non preload post => comments with include?" do
|
66
|
+
comment = Comment.last
|
67
|
+
Post.all.each do |post|
|
68
|
+
post.comments.include?(comment)
|
69
|
+
end
|
70
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
71
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
72
|
+
|
73
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
74
|
+
end
|
64
75
|
end
|
65
76
|
|
66
77
|
context "category => posts => comments" do
|
@@ -324,6 +335,15 @@ if !mongoid? && active_record3?
|
|
324
335
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Comment, :post)
|
325
336
|
end
|
326
337
|
|
338
|
+
it "should not detect non preload association with only one comment" do
|
339
|
+
Comment.first.post.category.name
|
340
|
+
|
341
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
342
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
343
|
+
|
344
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
345
|
+
end
|
346
|
+
|
327
347
|
it "should detect non preload association with post => category" do
|
328
348
|
Comment.includes(:post).each do |comment|
|
329
349
|
comment.post.category.name
|
@@ -371,7 +391,7 @@ if !mongoid? && active_record3?
|
|
371
391
|
comment.post.writer.newspaper.name
|
372
392
|
end
|
373
393
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
374
|
-
Bullet::Detector::Association.
|
394
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
375
395
|
|
376
396
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Writer, :newspaper)
|
377
397
|
end
|
@@ -61,6 +61,17 @@ if !mongoid? && active_record4?
|
|
61
61
|
|
62
62
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
63
63
|
end
|
64
|
+
|
65
|
+
it "should detect non preload post => comments with include?" do
|
66
|
+
comment = Comment.last
|
67
|
+
Post.all.each do |post|
|
68
|
+
post.comments.include?(comment)
|
69
|
+
end
|
70
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
71
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
72
|
+
|
73
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Post, :comments)
|
74
|
+
end
|
64
75
|
end
|
65
76
|
|
66
77
|
context "category => posts => comments" do
|
@@ -208,6 +219,20 @@ if !mongoid? && active_record4?
|
|
208
219
|
|
209
220
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
210
221
|
end
|
222
|
+
|
223
|
+
it "should not detect unused preload with category => posts" do
|
224
|
+
category = Category.first
|
225
|
+
category.draft_post.destroy!
|
226
|
+
post = category.draft_post
|
227
|
+
post.update_attributes!(link: true)
|
228
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
229
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
230
|
+
|
231
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
232
|
+
|
233
|
+
Support::SqliteSeed.setup_db
|
234
|
+
Support::SqliteSeed.seed_db
|
235
|
+
end
|
211
236
|
end
|
212
237
|
|
213
238
|
context "category => posts => writer" do
|
@@ -302,7 +327,7 @@ if !mongoid? && active_record4?
|
|
302
327
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
303
328
|
end
|
304
329
|
|
305
|
-
it "should detect unused preload with
|
330
|
+
it "should detect unused preload with comment => post" do
|
306
331
|
Comment.includes(:post).map(&:name)
|
307
332
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
308
333
|
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Comment, :post)
|
@@ -322,6 +347,15 @@ if !mongoid? && active_record4?
|
|
322
347
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Comment, :post)
|
323
348
|
end
|
324
349
|
|
350
|
+
it "should not detect non preload association with only one comment" do
|
351
|
+
Comment.first.post.category.name
|
352
|
+
|
353
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
354
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
355
|
+
|
356
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
357
|
+
end
|
358
|
+
|
325
359
|
it "should detect non preload association with post => category" do
|
326
360
|
Comment.includes(:post).each do |comment|
|
327
361
|
comment.post.category.name
|
@@ -369,7 +403,7 @@ if !mongoid? && active_record4?
|
|
369
403
|
comment.post.writer.newspaper.name
|
370
404
|
end
|
371
405
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
372
|
-
Bullet::Detector::Association.
|
406
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
373
407
|
|
374
408
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Writer, :newspaper)
|
375
409
|
end
|
@@ -504,6 +538,17 @@ if !mongoid? && active_record4?
|
|
504
538
|
end
|
505
539
|
end
|
506
540
|
|
541
|
+
describe Bullet::Detector::Association, "has_one => has_many" do
|
542
|
+
it "should not detect preload association" do
|
543
|
+
user = User.first
|
544
|
+
user.submission.replies.map(&:name)
|
545
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
546
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
547
|
+
|
548
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
507
552
|
describe Bullet::Detector::Association, "call one association that in possible objects" do
|
508
553
|
it "should not detect preload association" do
|
509
554
|
Post.all
|
data/spec/models/category.rb
CHANGED
data/spec/models/comment.rb
CHANGED
data/spec/models/post.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
class Post < ActiveRecord::Base
|
2
|
-
|
3
|
-
|
4
|
-
belongs_to :category
|
2
|
+
belongs_to :category, inverse_of: :posts
|
5
3
|
belongs_to :writer
|
6
4
|
has_many :comments, inverse_of: :post
|
7
5
|
|
6
|
+
validates :category, presence: true
|
7
|
+
|
8
8
|
scope :preload_comments, -> { includes(:comments) }
|
9
9
|
scope :in_category_name, ->(name) { where(['categories.name = ?', name]).includes(:category) }
|
10
|
+
scope :draft, -> { where(active: false) }
|
11
|
+
|
12
|
+
def link=(*)
|
13
|
+
comments.new
|
14
|
+
end
|
10
15
|
end
|
data/spec/models/submission.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -56,16 +56,16 @@ if active_record?
|
|
56
56
|
Support::SqliteSeed.seed_db
|
57
57
|
end
|
58
58
|
|
59
|
-
config.before(:
|
59
|
+
config.before(:example) do
|
60
60
|
Bullet.start_request
|
61
61
|
end
|
62
62
|
|
63
|
-
config.after(:
|
63
|
+
config.after(:example) do
|
64
64
|
Bullet.end_request
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
if ENV["
|
68
|
+
if ENV["BULLET_LOG"]
|
69
69
|
require 'logger'
|
70
70
|
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
71
71
|
end
|
@@ -96,7 +96,7 @@ if mongoid?
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
if ENV["
|
99
|
+
if ENV["BULLET_LOG"]
|
100
100
|
Mongoid.logger = Logger.new(STDOUT)
|
101
101
|
Moped.logger = Logger.new(STDOUT)
|
102
102
|
end
|
data/spec/support/sqlite_seed.rb
CHANGED
@@ -14,7 +14,7 @@ module Support
|
|
14
14
|
category2 = Category.create(:name => 'second')
|
15
15
|
|
16
16
|
post1 = category1.posts.create(:name => 'first', :writer => writer1)
|
17
|
-
post1a = category1.posts.create(:name => 'like first', :writer => writer2)
|
17
|
+
post1a = category1.posts.create(:name => 'like first', :writer => writer2, active: false)
|
18
18
|
post2 = category2.posts.create(:name => 'second', :writer => writer2)
|
19
19
|
|
20
20
|
comment1 = post1.comments.create(:name => 'first', :author => writer1)
|
@@ -82,10 +82,13 @@ module Support
|
|
82
82
|
user1 = User.create(:name => 'user1', :category => category1)
|
83
83
|
user2 = User.create(:name => 'user2', :category => category1)
|
84
84
|
|
85
|
-
submission1 =
|
86
|
-
submission2 =
|
87
|
-
|
88
|
-
|
85
|
+
submission1 = user1.create_submission(:name => "submission1")
|
86
|
+
submission2 = user2.create_submission(:name => "submission2")
|
87
|
+
|
88
|
+
submission1.replies.create(:name => 'reply1')
|
89
|
+
submission1.replies.create(:name => 'reply2')
|
90
|
+
submission2.replies.create(:name => 'reply3')
|
91
|
+
submission2.replies.create(:name => 'reply4')
|
89
92
|
end
|
90
93
|
|
91
94
|
def setup_db
|
@@ -191,6 +194,7 @@ module Support
|
|
191
194
|
t.column :name, :string
|
192
195
|
t.column :category_id, :integer
|
193
196
|
t.column :writer_id, :integer
|
197
|
+
t.column :active, :boolean, :default => true
|
194
198
|
end
|
195
199
|
|
196
200
|
create_table :relationships do |t|
|
@@ -211,9 +215,13 @@ module Support
|
|
211
215
|
t.column :name, :string
|
212
216
|
end
|
213
217
|
|
218
|
+
create_table :replies do |t|
|
219
|
+
t.column :name, :string
|
220
|
+
t.column :submission_id, :integer
|
221
|
+
end
|
222
|
+
|
214
223
|
create_table :submissions do |t|
|
215
224
|
t.column :name, :string
|
216
|
-
t.column :category_id, :integer
|
217
225
|
t.column :user_id, :integer
|
218
226
|
end
|
219
227
|
|
data/test.sh
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#bundle update rails && bundle exec rspec spec
|
2
2
|
#BUNDLE_GEMFILE=Gemfile.mongoid bundle update mongoid && BUNDLE_GEMFILE=Gemfile.mongoid bundle exec rspec spec
|
3
|
+
BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle exec rspec spec
|
3
4
|
BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle exec rspec spec
|
4
5
|
BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle && BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle exec rspec spec
|
5
6
|
BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle && BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle exec rspec spec
|
data/update.sh
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
BUNDLE_GEMFILE=Gemfile.rails-4.2 bundle update
|
2
|
+
BUNDLE_GEMFILE=Gemfile.rails-4.1 bundle update
|
3
|
+
BUNDLE_GEMFILE=Gemfile.rails-4.0 bundle update
|
4
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.2 bundle update
|
5
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.1 bundle update
|
6
|
+
BUNDLE_GEMFILE=Gemfile.rails-3.0 bundle update
|
7
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-4.0 bundle update
|
8
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-3.1 bundle update
|
9
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-3.0 bundle update
|
10
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.8 bundle update
|
11
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.7 bundle update
|
12
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.6 bundle update
|
13
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.5 bundle update
|
14
|
+
BUNDLE_GEMFILE=Gemfile.mongoid-2.4 bundle update
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_instructure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.14.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,16 +28,30 @@ dependencies:
|
|
28
28
|
name: uniform_notifier
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.9.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redcarpet
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
41
55
|
description: help to kill N+1 queries and unused eager loading, pretty formatter for
|
42
56
|
Instructure.
|
43
57
|
email:
|
@@ -48,7 +62,6 @@ extra_rdoc_files: []
|
|
48
62
|
files:
|
49
63
|
- ".gitignore"
|
50
64
|
- ".rspec"
|
51
|
-
- ".ruby-version"
|
52
65
|
- ".travis.yml"
|
53
66
|
- CHANGELOG.md
|
54
67
|
- Gemfile
|
@@ -66,6 +79,7 @@ files:
|
|
66
79
|
- Gemfile.rails-3.2
|
67
80
|
- Gemfile.rails-4.0
|
68
81
|
- Gemfile.rails-4.1
|
82
|
+
- Gemfile.rails-4.2
|
69
83
|
- Guardfile
|
70
84
|
- Hacking.md
|
71
85
|
- MIT-LICENSE
|
@@ -77,6 +91,7 @@ files:
|
|
77
91
|
- lib/bullet/active_record3x.rb
|
78
92
|
- lib/bullet/active_record4.rb
|
79
93
|
- lib/bullet/active_record41.rb
|
94
|
+
- lib/bullet/active_record42.rb
|
80
95
|
- lib/bullet/dependency.rb
|
81
96
|
- lib/bullet/detector.rb
|
82
97
|
- lib/bullet/detector/association.rb
|
@@ -150,6 +165,7 @@ files:
|
|
150
165
|
- spec/models/pet.rb
|
151
166
|
- spec/models/post.rb
|
152
167
|
- spec/models/relationship.rb
|
168
|
+
- spec/models/reply.rb
|
153
169
|
- spec/models/student.rb
|
154
170
|
- spec/models/submission.rb
|
155
171
|
- spec/models/teacher.rb
|
@@ -162,6 +178,7 @@ files:
|
|
162
178
|
- spec/support/sqlite_seed.rb
|
163
179
|
- tasks/bullet_tasks.rake
|
164
180
|
- test.sh
|
181
|
+
- update.sh
|
165
182
|
homepage: http://github.com/flyerhzm/bullet
|
166
183
|
licenses:
|
167
184
|
- MIT
|
@@ -182,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
199
|
version: 1.3.6
|
183
200
|
requirements: []
|
184
201
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.
|
202
|
+
rubygems_version: 2.2.2
|
186
203
|
signing_key:
|
187
204
|
specification_version: 4
|
188
205
|
summary: help to kill N+1 queries and unused eager loading, pretty formatter for Instructure.
|
@@ -234,6 +251,7 @@ test_files:
|
|
234
251
|
- spec/models/pet.rb
|
235
252
|
- spec/models/post.rb
|
236
253
|
- spec/models/relationship.rb
|
254
|
+
- spec/models/reply.rb
|
237
255
|
- spec/models/student.rb
|
238
256
|
- spec/models/submission.rb
|
239
257
|
- spec/models/teacher.rb
|
@@ -244,4 +262,3 @@ test_files:
|
|
244
262
|
- spec/support/mongo_seed.rb
|
245
263
|
- spec/support/rack_double.rb
|
246
264
|
- spec/support/sqlite_seed.rb
|
247
|
-
has_rdoc:
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.5
|