bullet 7.0.3 → 7.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/MIT-LICENSE +1 -1
- data/README.md +1 -1
- data/lib/bullet/active_record5.rb +6 -4
- data/lib/bullet/active_record52.rb +6 -4
- data/lib/bullet/active_record60.rb +5 -3
- data/lib/bullet/active_record61.rb +5 -3
- data/lib/bullet/active_record70.rb +5 -3
- data/lib/bullet/mongoid7x.rb +8 -10
- data/lib/bullet/version.rb +1 -1
- data/spec/integration/active_record/association_spec.rb +9 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ee8344236feb882d0359202c851abb8887b6b3bb31186f2b37329a41fbc3e96
|
4
|
+
data.tar.gz: 9d1aea1b67a6777c56b2548e93614ee051d5799e8caf9ecb0d48663a6a7b5bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f603fb2540b20dd0e5d5e519de308b9a264d264bbea6db9d7399c25d6912e053aa243cb877b98cfa123f3eca9142bc0fec1bf9b4ff41f411efd6a895f616916b
|
7
|
+
data.tar.gz: 1e000b7bb96d2479108bb67bc6ac6d4efdc3f337f76f42e8227d1b8b9394a7d38d09df0104ceb3ed7b6e9a98b570dc0f32d3eeff85277490e4ee0c552b577f5b
|
data/CHANGELOG.md
CHANGED
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -285,7 +285,7 @@ $ rails g scaffold comment name:string post_id:integer
|
|
285
285
|
$ bundle exec rake db:migrate
|
286
286
|
```
|
287
287
|
|
288
|
-
2\. Change `app/
|
288
|
+
2\. Change `app/models/post.rb` and `app/models/comment.rb`
|
289
289
|
|
290
290
|
```ruby
|
291
291
|
class Post < ActiveRecord::Base
|
@@ -177,10 +177,12 @@ module Bullet
|
|
177
177
|
if Bullet.start?
|
178
178
|
if is_a? ::ActiveRecord::Associations::ThroughAssociation
|
179
179
|
refl = reflection.through_reflection
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
180
|
+
association = owner.association(refl.name)
|
181
|
+
if association.loaded?
|
182
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, refl.name)
|
183
|
+
Array.wrap(association.target).each do |through_record|
|
184
|
+
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
185
|
+
end
|
184
186
|
end
|
185
187
|
|
186
188
|
if refl.through_reflection?
|
@@ -150,10 +150,12 @@ module Bullet
|
|
150
150
|
|
151
151
|
if Bullet.start?
|
152
152
|
if is_a? ::ActiveRecord::Associations::ThroughAssociation
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
153
|
+
association = owner.association(reflection.through_reflection.name)
|
154
|
+
if association.loaded?
|
155
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
|
156
|
+
Array.wrap(association.target).each do |through_record|
|
157
|
+
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
158
|
+
end
|
157
159
|
end
|
158
160
|
|
159
161
|
if reflection.through_reflection != through_reflection
|
@@ -177,10 +177,12 @@ module Bullet
|
|
177
177
|
|
178
178
|
if Bullet.start?
|
179
179
|
if is_a? ::ActiveRecord::Associations::ThroughAssociation
|
180
|
-
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
|
181
180
|
association = owner.association(reflection.through_reflection.name)
|
182
|
-
|
183
|
-
Bullet::Detector::NPlusOneQuery.call_association(
|
181
|
+
if association.loaded?
|
182
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
|
183
|
+
Array.wrap(association.target).each do |through_record|
|
184
|
+
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
185
|
+
end
|
184
186
|
end
|
185
187
|
|
186
188
|
if reflection.through_reflection != through_reflection
|
@@ -177,10 +177,12 @@ module Bullet
|
|
177
177
|
|
178
178
|
if Bullet.start?
|
179
179
|
if is_a? ::ActiveRecord::Associations::ThroughAssociation
|
180
|
-
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
|
181
180
|
association = owner.association(reflection.through_reflection.name)
|
182
|
-
|
183
|
-
Bullet::Detector::NPlusOneQuery.call_association(
|
181
|
+
if association.loaded?
|
182
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
|
183
|
+
Array.wrap(association.target).each do |through_record|
|
184
|
+
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
185
|
+
end
|
184
186
|
end
|
185
187
|
|
186
188
|
if reflection.through_reflection != through_reflection
|
@@ -180,10 +180,12 @@ module Bullet
|
|
180
180
|
|
181
181
|
if Bullet.start?
|
182
182
|
if is_a? ::ActiveRecord::Associations::ThroughAssociation
|
183
|
-
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
|
184
183
|
association = owner.association(reflection.through_reflection.name)
|
185
|
-
|
186
|
-
Bullet::Detector::NPlusOneQuery.call_association(
|
184
|
+
if association.loaded?
|
185
|
+
Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
|
186
|
+
Array.wrap(association.target).each do |through_record|
|
187
|
+
Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
|
188
|
+
end
|
187
189
|
end
|
188
190
|
|
189
191
|
if reflection.through_reflection != through_reflection
|
data/lib/bullet/mongoid7x.rb
CHANGED
@@ -4,22 +4,20 @@ module Bullet
|
|
4
4
|
module Mongoid
|
5
5
|
def self.enable
|
6
6
|
require 'mongoid'
|
7
|
+
require 'rubygems'
|
7
8
|
::Mongoid::Contextual::Mongo.class_eval do
|
8
9
|
alias_method :origin_first, :first
|
9
10
|
alias_method :origin_last, :last
|
10
11
|
alias_method :origin_each, :each
|
11
12
|
alias_method :origin_eager_load, :eager_load
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
result = origin_last(opts)
|
21
|
-
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
|
22
|
-
result
|
14
|
+
%i[first last].each do |context|
|
15
|
+
default = Gem::Version.new(::Mongoid::VERSION) >= Gem::Version.new('7.5') ? nil : {}
|
16
|
+
define_method(context) do |opts = default|
|
17
|
+
result = send(:"origin_#{context}", opts)
|
18
|
+
Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
|
19
|
+
result
|
20
|
+
end
|
23
21
|
end
|
24
22
|
|
25
23
|
def each(&block)
|
data/lib/bullet/version.rb
CHANGED
@@ -474,7 +474,15 @@ if active_record?
|
|
474
474
|
end
|
475
475
|
|
476
476
|
it 'should detect preload associations' do
|
477
|
-
Firm.
|
477
|
+
Firm.preload(:clients).each { |firm| firm.clients.map(&:name) }
|
478
|
+
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
479
|
+
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
480
|
+
|
481
|
+
expect(Bullet::Detector::Association).to be_completely_preloading_associations
|
482
|
+
end
|
483
|
+
|
484
|
+
it 'should detect eager load association' do
|
485
|
+
Firm.eager_load(:clients).each { |firm| firm.clients.map(&:name) }
|
478
486
|
Bullet::Detector::UnusedEagerLoading.check_unused_preload_associations
|
479
487
|
expect(Bullet::Detector::Association).not_to be_has_unused_preload_associations
|
480
488
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
195
|
- !ruby/object:Gem::Version
|
196
196
|
version: 1.3.6
|
197
197
|
requirements: []
|
198
|
-
rubygems_version: 3.3.
|
198
|
+
rubygems_version: 3.3.22
|
199
199
|
signing_key:
|
200
200
|
specification_version: 4
|
201
201
|
summary: help to kill N+1 queries and unused eager loading.
|