bullet 7.0.0 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +2 -3
- data/lib/bullet/active_record70.rb +14 -0
- data/lib/bullet/rack.rb +1 -0
- data/lib/bullet/version.rb +1 -1
- data/lib/bullet.rb +0 -45
- data/spec/bullet/rack_spec.rb +5 -0
- data/spec/bullet_spec.rb +0 -29
- data/spec/integration/active_record/association_spec.rb +10 -0
- data/spec/models/role.rb +7 -0
- data/spec/models/user.rb +1 -0
- data/spec/support/sqlite_seed.rb +18 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 823bcc1af2be934ec4f10df71ea2951223834d3146e9c323afada99ba4ae4254
|
4
|
+
data.tar.gz: 4cda048b45bd219d62bee22e0041027561c943d283ee262ea71686a15e6e4345
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a2398eb23da7201bb8ab3fb1dbea3d48089d6c51d4a0e473d25009841aab41c68a5b0c27fb6ac6b77084e2465a836a5b848ffda63a2ea3b457a9571b04d428f
|
7
|
+
data.tar.gz: ab3debd03dc9cafbbd8ef9237f747c67d14bf3d8bf116b7dbed4e145176cf3f10045862b32641036e9bb00caca6eee841c75f9b3defad83ca681d0d70a5c6f0d
|
data/.github/workflows/main.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -270,8 +270,7 @@ Bullet outputs some details info, to enable debug mode, set
|
|
270
270
|
## Demo
|
271
271
|
|
272
272
|
Bullet is designed to function as you browse through your application in development. To see it in action,
|
273
|
-
you can
|
274
|
-
follow these steps to create, detect, and fix example query problems.
|
273
|
+
you can follow these steps to create, detect, and fix example query problems.
|
275
274
|
|
276
275
|
1\. Create an example application
|
277
276
|
|
@@ -482,4 +481,4 @@ Meanwhile, there's a line appended to `log/bullet.log`
|
|
482
481
|
Post => [:comments]
|
483
482
|
```
|
484
483
|
|
485
|
-
Copyright (c) 2009 -
|
484
|
+
Copyright (c) 2009 - 2022 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
@@ -60,6 +60,20 @@ module Bullet
|
|
60
60
|
end
|
61
61
|
)
|
62
62
|
|
63
|
+
::ActiveRecord::Associations::Preloader::Batch.prepend(
|
64
|
+
Module.new do
|
65
|
+
def call
|
66
|
+
if Bullet.start?
|
67
|
+
@preloaders.each do |preloader|
|
68
|
+
preloader.records.each { |record| Bullet::Detector::Association.add_object_associations(record, preloader.associations) }
|
69
|
+
Bullet::Detector::UnusedEagerLoading.add_eager_loadings(preloader.records, preloader.associations)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
super
|
73
|
+
end
|
74
|
+
end
|
75
|
+
)
|
76
|
+
|
63
77
|
::ActiveRecord::Associations::Preloader::Branch.prepend(
|
64
78
|
Module.new do
|
65
79
|
def preloaders_for_reflection(reflection, reflection_records)
|
data/lib/bullet/rack.rb
CHANGED
@@ -42,6 +42,7 @@ module Bullet
|
|
42
42
|
def empty?(response)
|
43
43
|
# response may be ["Not Found"], ["Move Permanently"], etc, but
|
44
44
|
# those should not happen if the status is 200
|
45
|
+
return true if !response.respond_to?(:body) && !response.respond_to?(:first)
|
45
46
|
body = response_body(response)
|
46
47
|
body.nil? || body.empty?
|
47
48
|
end
|
data/lib/bullet/version.rb
CHANGED
data/lib/bullet.rb
CHANGED
@@ -120,51 +120,6 @@ module Bullet
|
|
120
120
|
@safelist = nil
|
121
121
|
end
|
122
122
|
|
123
|
-
def add_whitelist(options)
|
124
|
-
ActiveSupport::Deprecation.warn(<<~WARN.strip
|
125
|
-
add_whitelist is deprecated in favor of add_safelist. It will be removed from the next major release.
|
126
|
-
WARN
|
127
|
-
)
|
128
|
-
|
129
|
-
add_safelist(options)
|
130
|
-
end
|
131
|
-
|
132
|
-
def delete_whitelist(options)
|
133
|
-
ActiveSupport::Deprecation.warn(<<~WARN.strip
|
134
|
-
delete_whitelist is deprecated in favor of delete_safelist. It will be removed from the next major release.
|
135
|
-
WARN
|
136
|
-
)
|
137
|
-
|
138
|
-
delete_safelist(options)
|
139
|
-
end
|
140
|
-
|
141
|
-
def get_whitelist_associations(type, class_name)
|
142
|
-
ActiveSupport::Deprecation.warn(<<~WARN.strip
|
143
|
-
get_whitelist_associations is deprecated in favor of get_safelist_associations. It will be removed from the next major release.
|
144
|
-
WARN
|
145
|
-
)
|
146
|
-
|
147
|
-
get_safelist_associations(type, class_name)
|
148
|
-
end
|
149
|
-
|
150
|
-
def reset_whitelist
|
151
|
-
ActiveSupport::Deprecation.warn(<<~WARN.strip
|
152
|
-
reset_whitelist is deprecated in favor of reset_safelist. It will be removed from the next major release.
|
153
|
-
WARN
|
154
|
-
)
|
155
|
-
|
156
|
-
reset_safelist
|
157
|
-
end
|
158
|
-
|
159
|
-
def clear_whitelist
|
160
|
-
ActiveSupport::Deprecation.warn(<<~WARN.strip
|
161
|
-
clear_whitelist is deprecated in favor of clear_safelist. It will be removed from the next major release.
|
162
|
-
WARN
|
163
|
-
)
|
164
|
-
|
165
|
-
clear_safelist
|
166
|
-
end
|
167
|
-
|
168
123
|
def bullet_logger=(active)
|
169
124
|
if active
|
170
125
|
require 'fileutils'
|
data/spec/bullet/rack_spec.rb
CHANGED
data/spec/bullet_spec.rb
CHANGED
@@ -83,15 +83,6 @@ describe Bullet, focused: true do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe '#add_whitelist' do
|
87
|
-
context "for 'special' class names" do
|
88
|
-
it 'is added to the safelist successfully' do
|
89
|
-
Bullet.add_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
90
|
-
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to include :department
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
86
|
describe '#delete_safelist' do
|
96
87
|
context "for 'special' class names" do
|
97
88
|
it 'is deleted from the safelist successfully' do
|
@@ -112,26 +103,6 @@ describe Bullet, focused: true do
|
|
112
103
|
end
|
113
104
|
end
|
114
105
|
|
115
|
-
describe '#delete_whitelist' do
|
116
|
-
context "for 'special' class names" do
|
117
|
-
it 'is deleted from the safelist successfully' do
|
118
|
-
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
119
|
-
Bullet.delete_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
120
|
-
expect(Bullet.safelist[:n_plus_one_query]).to eq({})
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'when exists multiple definitions' do
|
125
|
-
it 'is deleted from the safelist successfully' do
|
126
|
-
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :department)
|
127
|
-
Bullet.add_safelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
|
128
|
-
Bullet.delete_whitelist(type: :n_plus_one_query, class_name: 'Klass', association: :team)
|
129
|
-
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to include :department
|
130
|
-
expect(Bullet.get_safelist_associations(:n_plus_one_query, 'Klass')).to_not include :team
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
106
|
describe '#perform_out_of_channel_notifications' do
|
136
107
|
let(:notification) { double }
|
137
108
|
|
@@ -451,6 +451,16 @@ if active_record?
|
|
451
451
|
expect(Bullet::Detector::Association).to be_detecting_unpreloaded_association_for(Student, :teachers)
|
452
452
|
end
|
453
453
|
end
|
454
|
+
|
455
|
+
context 'user => roles' do
|
456
|
+
it 'should detect preload associations' do
|
457
|
+
User.first.roles.includes(:resource).each { |role| role.resource }
|
458
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
459
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
460
|
+
|
461
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
462
|
+
end
|
463
|
+
end
|
454
464
|
end
|
455
465
|
|
456
466
|
describe Bullet::Detector::Association, 'has_many :through' do
|
data/spec/models/role.rb
ADDED
data/spec/models/user.rb
CHANGED
data/spec/support/sqlite_seed.rb
CHANGED
@@ -92,9 +92,16 @@ module Support
|
|
92
92
|
page3 = Page.create(name: 'page3', parent_id: folder2.id, author_id: author2.id)
|
93
93
|
page4 = Page.create(name: 'page4', parent_id: folder2.id, author_id: author2.id)
|
94
94
|
|
95
|
+
role1 = Role.create(name: 'Amdin')
|
96
|
+
role2 = Role.create(name: 'User')
|
97
|
+
|
95
98
|
user1 = User.create(name: 'user1', category: category1)
|
96
99
|
user2 = User.create(name: 'user2', category: category1)
|
97
100
|
|
101
|
+
user1.roles << role1
|
102
|
+
user1.roles << role2
|
103
|
+
user2.roles << role2
|
104
|
+
|
98
105
|
submission1 = user1.create_submission(name: 'submission1')
|
99
106
|
submission2 = user2.create_submission(name: 'submission2')
|
100
107
|
|
@@ -246,6 +253,17 @@ module Support
|
|
246
253
|
t.column :submission_id, :integer
|
247
254
|
end
|
248
255
|
|
256
|
+
create_table :roles do |t|
|
257
|
+
t.column :name, :string
|
258
|
+
t.column :resource_id, :integer
|
259
|
+
t.column :resource_type, :string
|
260
|
+
end
|
261
|
+
|
262
|
+
create_table :roles_users do |t|
|
263
|
+
t.column :role_id, :integer
|
264
|
+
t.column :user_id, :integer
|
265
|
+
end
|
266
|
+
|
249
267
|
create_table :submissions do |t|
|
250
268
|
t.column :name, :string
|
251
269
|
t.column :user_id, :integer
|
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: 7.0.
|
4
|
+
version: 7.0.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:
|
11
|
+
date: 2022-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- spec/models/post.rb
|
161
161
|
- spec/models/relationship.rb
|
162
162
|
- spec/models/reply.rb
|
163
|
+
- spec/models/role.rb
|
163
164
|
- spec/models/student.rb
|
164
165
|
- spec/models/submission.rb
|
165
166
|
- spec/models/teacher.rb
|
@@ -194,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
195
|
- !ruby/object:Gem::Version
|
195
196
|
version: 1.3.6
|
196
197
|
requirements: []
|
197
|
-
rubygems_version: 3.2.
|
198
|
+
rubygems_version: 3.2.32
|
198
199
|
signing_key:
|
199
200
|
specification_version: 4
|
200
201
|
summary: help to kill N+1 queries and unused eager loading.
|
@@ -249,6 +250,7 @@ test_files:
|
|
249
250
|
- spec/models/post.rb
|
250
251
|
- spec/models/relationship.rb
|
251
252
|
- spec/models/reply.rb
|
253
|
+
- spec/models/role.rb
|
252
254
|
- spec/models/student.rb
|
253
255
|
- spec/models/submission.rb
|
254
256
|
- spec/models/teacher.rb
|