bullet 5.5.0 → 6.1.5
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 +5 -5
- data/.github/workflows/main.yml +66 -0
- data/CHANGELOG.md +83 -1
- data/Gemfile +6 -1
- data/Gemfile.mongoid-7.0 +15 -0
- data/Gemfile.rails-4.0 +1 -1
- data/Gemfile.rails-4.1 +1 -1
- data/Gemfile.rails-4.2 +1 -1
- data/Gemfile.rails-5.0 +2 -2
- data/Gemfile.rails-5.1 +15 -0
- data/Gemfile.rails-5.2 +15 -0
- data/Gemfile.rails-6.0 +15 -0
- data/Gemfile.rails-6.1 +15 -0
- data/Guardfile +2 -2
- data/Hacking.md +1 -1
- data/README.md +58 -37
- data/Rakefile +20 -21
- data/bullet.gemspec +21 -15
- data/lib/bullet/active_job.rb +13 -0
- data/lib/bullet/active_record4.rb +15 -34
- data/lib/bullet/active_record41.rb +14 -31
- data/lib/bullet/active_record42.rb +23 -36
- data/lib/bullet/active_record5.rb +178 -158
- data/lib/bullet/active_record52.rb +251 -0
- data/lib/bullet/active_record60.rb +278 -0
- data/lib/bullet/active_record61.rb +278 -0
- data/lib/bullet/bullet_xhr.js +64 -0
- data/lib/bullet/dependency.rb +60 -32
- data/lib/bullet/detector/association.rb +41 -32
- data/lib/bullet/detector/base.rb +2 -0
- data/lib/bullet/detector/counter_cache.rb +25 -17
- data/lib/bullet/detector/n_plus_one_query.rb +38 -24
- data/lib/bullet/detector/unused_eager_loading.rb +35 -26
- data/lib/bullet/detector.rb +2 -0
- data/lib/bullet/ext/object.rb +9 -5
- data/lib/bullet/ext/string.rb +3 -1
- data/lib/bullet/mongoid4x.rb +9 -8
- data/lib/bullet/mongoid5x.rb +9 -8
- data/lib/bullet/mongoid6x.rb +13 -12
- data/lib/bullet/mongoid7x.rb +57 -0
- data/lib/bullet/notification/base.rb +28 -25
- data/lib/bullet/notification/counter_cache.rb +3 -1
- data/lib/bullet/notification/n_plus_one_query.rb +8 -7
- data/lib/bullet/notification/unused_eager_loading.rb +8 -7
- data/lib/bullet/notification.rb +4 -1
- data/lib/bullet/notification_collector.rb +2 -1
- data/lib/bullet/rack.rb +66 -35
- data/lib/bullet/registry/association.rb +2 -0
- data/lib/bullet/registry/base.rb +2 -0
- data/lib/bullet/registry/object.rb +2 -0
- data/lib/bullet/registry.rb +2 -0
- data/lib/bullet/stack_trace_filter.rb +50 -20
- data/lib/bullet/version.rb +3 -2
- data/lib/bullet.rb +136 -55
- data/lib/generators/bullet/install_generator.rb +48 -0
- data/perf/benchmark.rb +19 -22
- data/rails/init.rb +2 -0
- data/spec/bullet/detector/association_spec.rb +6 -4
- data/spec/bullet/detector/base_spec.rb +2 -0
- data/spec/bullet/detector/counter_cache_spec.rb +17 -15
- data/spec/bullet/detector/n_plus_one_query_spec.rb +75 -46
- data/spec/bullet/detector/unused_eager_loading_spec.rb +45 -26
- data/spec/bullet/ext/object_spec.rb +18 -11
- data/spec/bullet/ext/string_spec.rb +7 -5
- data/spec/bullet/notification/base_spec.rb +38 -39
- data/spec/bullet/notification/counter_cache_spec.rb +5 -3
- data/spec/bullet/notification/n_plus_one_query_spec.rb +20 -5
- data/spec/bullet/notification/unused_eager_loading_spec.rb +9 -3
- data/spec/bullet/notification_collector_spec.rb +12 -10
- data/spec/bullet/rack_spec.rb +200 -48
- data/spec/bullet/registry/association_spec.rb +12 -10
- data/spec/bullet/registry/base_spec.rb +22 -20
- data/spec/bullet/registry/object_spec.rb +6 -4
- data/spec/bullet_spec.rb +64 -33
- data/spec/integration/{active_record4 → active_record}/association_spec.rb +238 -223
- data/spec/integration/counter_cache_spec.rb +26 -44
- data/spec/integration/mongoid/association_spec.rb +53 -65
- data/spec/models/address.rb +2 -0
- data/spec/models/attachment.rb +5 -0
- data/spec/models/author.rb +2 -0
- data/spec/models/base_user.rb +2 -0
- data/spec/models/category.rb +2 -0
- data/spec/models/city.rb +2 -0
- data/spec/models/client.rb +4 -0
- data/spec/models/comment.rb +3 -1
- data/spec/models/company.rb +2 -0
- data/spec/models/country.rb +2 -0
- data/spec/models/deal.rb +5 -0
- data/spec/models/document.rb +4 -2
- data/spec/models/entry.rb +2 -0
- data/spec/models/firm.rb +3 -0
- data/spec/models/folder.rb +2 -0
- data/spec/models/group.rb +4 -0
- data/spec/models/mongoid/address.rb +3 -1
- data/spec/models/mongoid/category.rb +4 -2
- data/spec/models/mongoid/comment.rb +3 -1
- data/spec/models/mongoid/company.rb +3 -1
- data/spec/models/mongoid/entry.rb +3 -1
- data/spec/models/mongoid/post.rb +6 -4
- data/spec/models/mongoid/user.rb +2 -0
- data/spec/models/newspaper.rb +3 -1
- data/spec/models/page.rb +2 -0
- data/spec/models/person.rb +2 -0
- data/spec/models/pet.rb +2 -0
- data/spec/models/post.rb +19 -0
- data/spec/models/relationship.rb +2 -0
- data/spec/models/reply.rb +2 -0
- data/spec/models/student.rb +2 -0
- data/spec/models/submission.rb +3 -0
- data/spec/models/teacher.rb +2 -0
- data/spec/models/user.rb +3 -0
- data/spec/models/writer.rb +2 -0
- data/spec/spec_helper.rb +19 -23
- data/spec/support/bullet_ext.rb +10 -9
- data/spec/support/mongo_seed.rb +38 -57
- data/spec/support/rack_double.rb +13 -19
- data/spec/support/sqlite_seed.rb +104 -76
- data/tasks/bullet_tasks.rake +4 -2
- data/test.sh +5 -0
- data/update.sh +3 -0
- metadata +34 -17
- data/.travis.yml +0 -16
- data/spec/integration/active_record5/association_spec.rb +0 -768
|
@@ -1,84 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
if !mongoid? && active_record?
|
|
4
6
|
describe Bullet::Detector::CounterCache do
|
|
5
|
-
before(:each)
|
|
6
|
-
Bullet.start_request
|
|
7
|
-
end
|
|
7
|
+
before(:each) { Bullet.start_request }
|
|
8
8
|
|
|
9
|
-
after(:each)
|
|
10
|
-
Bullet.end_request
|
|
11
|
-
end
|
|
9
|
+
after(:each) { Bullet.end_request }
|
|
12
10
|
|
|
13
|
-
it
|
|
14
|
-
Country.all.each
|
|
15
|
-
country.cities.size
|
|
16
|
-
end
|
|
11
|
+
it 'should need counter cache with all cities' do
|
|
12
|
+
Country.all.each { |country| country.cities.size }
|
|
17
13
|
expect(Bullet.collected_counter_cache_notifications).not_to be_empty
|
|
18
14
|
end
|
|
19
15
|
|
|
20
|
-
it
|
|
21
|
-
Person.all.each
|
|
22
|
-
person.pets.size
|
|
23
|
-
end
|
|
16
|
+
it 'should not need counter cache if already define counter_cache' do
|
|
17
|
+
Person.all.each { |person| person.pets.size }
|
|
24
18
|
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
25
19
|
end
|
|
26
20
|
|
|
27
|
-
it
|
|
21
|
+
it 'should not need counter cache with only one object' do
|
|
28
22
|
Country.first.cities.size
|
|
29
23
|
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
30
24
|
end
|
|
31
25
|
|
|
32
|
-
it
|
|
33
|
-
Country.includes(:cities).each
|
|
34
|
-
country.cities.empty?
|
|
35
|
-
end
|
|
26
|
+
it 'should not need counter cache without size' do
|
|
27
|
+
Country.includes(:cities).each { |country| country.cities.empty? }
|
|
36
28
|
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
37
29
|
end
|
|
38
30
|
|
|
39
|
-
if active_record5?
|
|
40
|
-
it
|
|
41
|
-
Client.all.each
|
|
42
|
-
client.firms.size
|
|
43
|
-
end
|
|
31
|
+
if active_record5? || active_record6?
|
|
32
|
+
it 'should not need counter cache for has_many through' do
|
|
33
|
+
Client.all.each { |client| client.firms.size }
|
|
44
34
|
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
45
35
|
end
|
|
46
36
|
else
|
|
47
|
-
it
|
|
48
|
-
Client.all.each
|
|
49
|
-
client.firms.size
|
|
50
|
-
end
|
|
37
|
+
it 'should need counter cache for has_many through' do
|
|
38
|
+
Client.all.each { |client| client.firms.size }
|
|
51
39
|
expect(Bullet.collected_counter_cache_notifications).not_to be_empty
|
|
52
40
|
end
|
|
53
41
|
end
|
|
54
42
|
|
|
55
|
-
it
|
|
56
|
-
Country.all.each
|
|
57
|
-
country.cities.where(:name => 'first').size
|
|
58
|
-
end
|
|
43
|
+
it 'should not need counter cache with part of cities' do
|
|
44
|
+
Country.all.each { |country| country.cities.where(name: 'first').size }
|
|
59
45
|
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
60
46
|
end
|
|
61
47
|
|
|
62
|
-
context
|
|
48
|
+
context 'disable' do
|
|
63
49
|
before { Bullet.counter_cache_enable = false }
|
|
64
50
|
after { Bullet.counter_cache_enable = true }
|
|
65
51
|
|
|
66
|
-
it
|
|
67
|
-
Country.all.each
|
|
68
|
-
country.cities.size
|
|
69
|
-
end
|
|
52
|
+
it 'should not detect counter cache' do
|
|
53
|
+
Country.all.each { |country| country.cities.size }
|
|
70
54
|
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
71
55
|
end
|
|
72
56
|
end
|
|
73
57
|
|
|
74
|
-
context
|
|
75
|
-
before { Bullet.
|
|
76
|
-
after { Bullet.
|
|
58
|
+
context 'safelist' do
|
|
59
|
+
before { Bullet.add_safelist type: :counter_cache, class_name: 'Country', association: :cities }
|
|
60
|
+
after { Bullet.clear_safelist }
|
|
77
61
|
|
|
78
|
-
it
|
|
79
|
-
Country.all.each
|
|
80
|
-
country.cities.size
|
|
81
|
-
end
|
|
62
|
+
it 'should not detect counter cache' do
|
|
63
|
+
Country.all.each { |country| country.cities.size }
|
|
82
64
|
expect(Bullet.collected_counter_cache_notifications).to be_empty
|
|
83
65
|
end
|
|
84
66
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
if mongoid?
|
|
4
6
|
describe Bullet::Detector::Association do
|
|
5
7
|
context 'embeds_many' do
|
|
6
|
-
context
|
|
7
|
-
it
|
|
8
|
-
Mongoid::Post.all.each
|
|
9
|
-
post.users.map(&:name)
|
|
10
|
-
end
|
|
8
|
+
context 'posts => users' do
|
|
9
|
+
it 'should detect nothing' do
|
|
10
|
+
Mongoid::Post.all.each { |post| post.users.map(&:name) }
|
|
11
11
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
12
12
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
13
13
|
|
|
@@ -17,28 +17,24 @@ if mongoid?
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
context 'has_many' do
|
|
20
|
-
context
|
|
21
|
-
it
|
|
22
|
-
Mongoid::Post.all.each
|
|
23
|
-
post.comments.map(&:name)
|
|
24
|
-
end
|
|
20
|
+
context 'posts => comments' do
|
|
21
|
+
it 'should detect non preload posts => comments' do
|
|
22
|
+
Mongoid::Post.all.each { |post| post.comments.map(&:name) }
|
|
25
23
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
26
24
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
27
25
|
|
|
28
26
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Post, :comments)
|
|
29
27
|
end
|
|
30
28
|
|
|
31
|
-
it
|
|
32
|
-
Mongoid::Post.includes(:comments).each
|
|
33
|
-
post.comments.map(&:name)
|
|
34
|
-
end
|
|
29
|
+
it 'should detect preload post => comments' do
|
|
30
|
+
Mongoid::Post.includes(:comments).each { |post| post.comments.map(&:name) }
|
|
35
31
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
36
32
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
37
33
|
|
|
38
34
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
39
35
|
end
|
|
40
36
|
|
|
41
|
-
it
|
|
37
|
+
it 'should detect unused preload post => comments' do
|
|
42
38
|
Mongoid::Post.includes(:comments).map(&:name)
|
|
43
39
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
44
40
|
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
@@ -46,7 +42,7 @@ if mongoid?
|
|
|
46
42
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
47
43
|
end
|
|
48
44
|
|
|
49
|
-
it
|
|
45
|
+
it 'should not detect unused preload post => comments' do
|
|
50
46
|
Mongoid::Post.all.map(&:name)
|
|
51
47
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
52
48
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
@@ -55,8 +51,8 @@ if mongoid?
|
|
|
55
51
|
end
|
|
56
52
|
end
|
|
57
53
|
|
|
58
|
-
context
|
|
59
|
-
it
|
|
54
|
+
context 'category => posts, category => entries' do
|
|
55
|
+
it 'should detect non preload with category => [posts, entries]' do
|
|
60
56
|
Mongoid::Category.all.each do |category|
|
|
61
57
|
category.posts.map(&:name)
|
|
62
58
|
category.entries.map(&:name)
|
|
@@ -68,7 +64,7 @@ if mongoid?
|
|
|
68
64
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
|
|
69
65
|
end
|
|
70
66
|
|
|
71
|
-
it
|
|
67
|
+
it 'should detect preload with category => posts, but not with category => entries' do
|
|
72
68
|
Mongoid::Category.includes(:posts).each do |category|
|
|
73
69
|
category.posts.map(&:name)
|
|
74
70
|
category.entries.map(&:name)
|
|
@@ -76,11 +72,14 @@ if mongoid?
|
|
|
76
72
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
77
73
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
78
74
|
|
|
79
|
-
expect(Bullet::Detector::Association).not_to be_detecting_unpreloaded_association_for(
|
|
75
|
+
expect(Bullet::Detector::Association).not_to be_detecting_unpreloaded_association_for(
|
|
76
|
+
Mongoid::Category,
|
|
77
|
+
:posts
|
|
78
|
+
)
|
|
80
79
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Category, :entries)
|
|
81
80
|
end
|
|
82
81
|
|
|
83
|
-
it
|
|
82
|
+
it 'should detect preload with category => [posts, entries]' do
|
|
84
83
|
Mongoid::Category.includes(:posts, :entries).each do |category|
|
|
85
84
|
category.posts.map(&:name)
|
|
86
85
|
category.entries.map(&:name)
|
|
@@ -91,7 +90,7 @@ if mongoid?
|
|
|
91
90
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
92
91
|
end
|
|
93
92
|
|
|
94
|
-
it
|
|
93
|
+
it 'should detect unused preload with category => [posts, entries]' do
|
|
95
94
|
Mongoid::Category.includes(:posts, :entries).map(&:name)
|
|
96
95
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
97
96
|
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :posts)
|
|
@@ -100,10 +99,8 @@ if mongoid?
|
|
|
100
99
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
101
100
|
end
|
|
102
101
|
|
|
103
|
-
it
|
|
104
|
-
Mongoid::Category.includes(:posts, :entries).each
|
|
105
|
-
category.posts.map(&:name)
|
|
106
|
-
end
|
|
102
|
+
it 'should detect unused preload with category => entries, but not with category => posts' do
|
|
103
|
+
Mongoid::Category.includes(:posts, :entries).each { |category| category.posts.map(&:name) }
|
|
107
104
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
108
105
|
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Mongoid::Category, :posts)
|
|
109
106
|
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Category, :entries)
|
|
@@ -112,18 +109,16 @@ if mongoid?
|
|
|
112
109
|
end
|
|
113
110
|
end
|
|
114
111
|
|
|
115
|
-
context
|
|
116
|
-
it
|
|
117
|
-
Mongoid::Post.includes(:comments).each
|
|
118
|
-
post.comments.first.name
|
|
119
|
-
end
|
|
112
|
+
context 'post => comment' do
|
|
113
|
+
it 'should detect unused preload with post => comments' do
|
|
114
|
+
Mongoid::Post.includes(:comments).each { |post| post.comments.first.name }
|
|
120
115
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
121
116
|
expect(Bullet::Detector::Association).not_to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
122
117
|
|
|
123
118
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
124
119
|
end
|
|
125
120
|
|
|
126
|
-
it
|
|
121
|
+
it 'should detect preload with post => comments' do
|
|
127
122
|
Mongoid::Post.first.comments.map(&:name)
|
|
128
123
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
129
124
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
@@ -132,18 +127,16 @@ if mongoid?
|
|
|
132
127
|
end
|
|
133
128
|
end
|
|
134
129
|
|
|
135
|
-
context
|
|
136
|
-
it
|
|
137
|
-
Mongoid::Post.preload_comments.each
|
|
138
|
-
post.comments.map(&:name)
|
|
139
|
-
end
|
|
130
|
+
context 'scope preload_comments' do
|
|
131
|
+
it 'should detect preload post => comments with scope' do
|
|
132
|
+
Mongoid::Post.preload_comments.each { |post| post.comments.map(&:name) }
|
|
140
133
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
141
134
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
142
135
|
|
|
143
136
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
144
137
|
end
|
|
145
138
|
|
|
146
|
-
it
|
|
139
|
+
it 'should detect unused preload with scope' do
|
|
147
140
|
Mongoid::Post.preload_comments.map(&:name)
|
|
148
141
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
149
142
|
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Post, :comments)
|
|
@@ -154,18 +147,16 @@ if mongoid?
|
|
|
154
147
|
end
|
|
155
148
|
|
|
156
149
|
context 'belongs_to' do
|
|
157
|
-
context
|
|
158
|
-
it
|
|
159
|
-
Mongoid::Comment.all.each
|
|
160
|
-
comment.post.name
|
|
161
|
-
end
|
|
150
|
+
context 'comment => post' do
|
|
151
|
+
it 'should detect non preload with comment => post' do
|
|
152
|
+
Mongoid::Comment.all.each { |comment| comment.post.name }
|
|
162
153
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
163
154
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
164
155
|
|
|
165
156
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Mongoid::Comment, :post)
|
|
166
157
|
end
|
|
167
158
|
|
|
168
|
-
it
|
|
159
|
+
it 'should detect preload with one comment => post' do
|
|
169
160
|
Mongoid::Comment.first.post.name
|
|
170
161
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
171
162
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
@@ -173,17 +164,15 @@ if mongoid?
|
|
|
173
164
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
174
165
|
end
|
|
175
166
|
|
|
176
|
-
it
|
|
177
|
-
Mongoid::Comment.includes(:post).each
|
|
178
|
-
comment.post.name
|
|
179
|
-
end
|
|
167
|
+
it 'should detect preload with comment => post' do
|
|
168
|
+
Mongoid::Comment.includes(:post).each { |comment| comment.post.name }
|
|
180
169
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
181
170
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
182
171
|
|
|
183
172
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
184
173
|
end
|
|
185
174
|
|
|
186
|
-
it
|
|
175
|
+
it 'should not detect preload with comment => post' do
|
|
187
176
|
Mongoid::Comment.all.map(&:name)
|
|
188
177
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
189
178
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
@@ -191,7 +180,7 @@ if mongoid?
|
|
|
191
180
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
192
181
|
end
|
|
193
182
|
|
|
194
|
-
it
|
|
183
|
+
it 'should detect unused preload with comments => post' do
|
|
195
184
|
Mongoid::Comment.includes(:post).map(&:name)
|
|
196
185
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
197
186
|
expect(Bullet::Detector::Association).to be_unused_preload_associations_for(Mongoid::Comment, :post)
|
|
@@ -201,31 +190,30 @@ if mongoid?
|
|
|
201
190
|
end
|
|
202
191
|
end
|
|
203
192
|
|
|
204
|
-
context
|
|
205
|
-
context
|
|
193
|
+
context 'has_one' do
|
|
194
|
+
context 'company => address' do
|
|
206
195
|
if Mongoid::VERSION !~ /\A3.0/
|
|
207
|
-
it
|
|
208
|
-
Mongoid::Company.all.each
|
|
209
|
-
company.address.name
|
|
210
|
-
end
|
|
196
|
+
it 'should detect non preload association' do
|
|
197
|
+
Mongoid::Company.all.each { |company| company.address.name }
|
|
211
198
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
212
199
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
213
200
|
|
|
214
|
-
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(
|
|
201
|
+
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(
|
|
202
|
+
Mongoid::Company,
|
|
203
|
+
:address
|
|
204
|
+
)
|
|
215
205
|
end
|
|
216
206
|
end
|
|
217
207
|
|
|
218
|
-
it
|
|
219
|
-
Mongoid::Company.includes(:address).each
|
|
220
|
-
company.address.name
|
|
221
|
-
end
|
|
208
|
+
it 'should detect preload association' do
|
|
209
|
+
Mongoid::Company.includes(:address).each { |company| company.address.name }
|
|
222
210
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
223
211
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
224
212
|
|
|
225
213
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
226
214
|
end
|
|
227
215
|
|
|
228
|
-
it
|
|
216
|
+
it 'should not detect preload association' do
|
|
229
217
|
Mongoid::Company.all.map(&:name)
|
|
230
218
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
231
219
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
|
@@ -233,7 +221,7 @@ if mongoid?
|
|
|
233
221
|
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
|
234
222
|
end
|
|
235
223
|
|
|
236
|
-
it
|
|
224
|
+
it 'should detect unused preload association' do
|
|
237
225
|
criteria = Mongoid::Company.includes(:address)
|
|
238
226
|
criteria.map(&:name)
|
|
239
227
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
|
@@ -244,8 +232,8 @@ if mongoid?
|
|
|
244
232
|
end
|
|
245
233
|
end
|
|
246
234
|
|
|
247
|
-
context
|
|
248
|
-
it
|
|
235
|
+
context 'call one association that in possible objects' do
|
|
236
|
+
it 'should not detect preload association' do
|
|
249
237
|
Mongoid::Post.all
|
|
250
238
|
Mongoid::Post.first.comments.map(&:name)
|
|
251
239
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
data/spec/models/address.rb
CHANGED
data/spec/models/author.rb
CHANGED
data/spec/models/base_user.rb
CHANGED
data/spec/models/category.rb
CHANGED
data/spec/models/city.rb
CHANGED
data/spec/models/client.rb
CHANGED
data/spec/models/comment.rb
CHANGED
data/spec/models/company.rb
CHANGED
data/spec/models/country.rb
CHANGED
data/spec/models/deal.rb
ADDED
data/spec/models/document.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Document < ActiveRecord::Base
|
|
2
|
-
has_many :children, class_name:
|
|
3
|
-
belongs_to :parent, class_name:
|
|
4
|
+
has_many :children, class_name: 'Document', foreign_key: 'parent_id'
|
|
5
|
+
belongs_to :parent, class_name: 'Document', foreign_key: 'parent_id'
|
|
4
6
|
belongs_to :author
|
|
5
7
|
end
|
data/spec/models/entry.rb
CHANGED
data/spec/models/firm.rb
CHANGED
data/spec/models/folder.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Mongoid::Category
|
|
2
4
|
include Mongoid::Document
|
|
3
5
|
|
|
4
6
|
field :name
|
|
5
7
|
|
|
6
|
-
has_many :posts, :
|
|
7
|
-
has_many :entries, :
|
|
8
|
+
has_many :posts, class_name: 'Mongoid::Post'
|
|
9
|
+
has_many :entries, class_name: 'Mongoid::Entry'
|
|
8
10
|
end
|
data/spec/models/mongoid/post.rb
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
class Mongoid::Post
|
|
2
4
|
include Mongoid::Document
|
|
3
5
|
|
|
4
6
|
field :name
|
|
5
7
|
|
|
6
|
-
has_many :comments, :
|
|
7
|
-
belongs_to :category, :
|
|
8
|
+
has_many :comments, class_name: 'Mongoid::Comment'
|
|
9
|
+
belongs_to :category, class_name: 'Mongoid::Category'
|
|
8
10
|
|
|
9
|
-
embeds_many :users, :
|
|
11
|
+
embeds_many :users, class_name: 'Mongoid::User'
|
|
10
12
|
|
|
11
|
-
scope :preload_comments,
|
|
13
|
+
scope :preload_comments, -> { includes(:comments) }
|
|
12
14
|
end
|
data/spec/models/mongoid/user.rb
CHANGED
data/spec/models/newspaper.rb
CHANGED
data/spec/models/page.rb
CHANGED
data/spec/models/person.rb
CHANGED