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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad1f81292cc89778a41c6dd178bbfb6342fe1b69c4e57c3fdad0d8003d97b525
4
- data.tar.gz: 5c1c8113f6e03ecdb449bce5e12273b969f29c323a5bb802c13c0539ea439a69
3
+ metadata.gz: 1ee8344236feb882d0359202c851abb8887b6b3bb31186f2b37329a41fbc3e96
4
+ data.tar.gz: 9d1aea1b67a6777c56b2548e93614ee051d5799e8caf9ecb0d48663a6a7b5bd8
5
5
  SHA512:
6
- metadata.gz: 1f0d4d73910f96ab8c6ae5b6b1bc58de547c2c32a7c689c2984778465dae29d2c2cae81c23699b3848d2eaef30223db66bcca6ccb421b9078d5616f497421d45
7
- data.tar.gz: 3b9001966918da22bfe7b2960526ac0db471a75e79e7939b099bebe3dde1fb27ea69b1afbdec0fcc98a6cb4260b845b5551a1a07cec036207c885be4e14ef7b9
6
+ metadata.gz: f603fb2540b20dd0e5d5e519de308b9a264d264bbea6db9d7399c25d6912e053aa243cb877b98cfa123f3eca9142bc0fec1bf9b4ff41f411efd6a895f616916b
7
+ data.tar.gz: 1e000b7bb96d2479108bb67bc6ac6d4efdc3f337f76f42e8227d1b8b9394a7d38d09df0104ceb3ed7b6e9a98b570dc0f32d3eeff85277490e4ee0c552b577f5b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Next Release
2
2
 
3
+ ## 7.0.4 (11/28/2022)
4
+
5
+ * Fix `eager_load` `has_many :through` false positives
6
+ * mongoid7x: add dynamic methods
7
+
3
8
  ## 7.0.3 (08/13/2022)
4
9
 
5
10
  * Replace `Array()` with `Array.wrap()`
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 - 2010 Richard Huang (flyerhzm@gmail.com)
1
+ Copyright (c) 2009 - 2022 Richard Huang (flyerhzm@gmail.com)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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/model/post.rb` and `app/model/comment.rb`
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
- Bullet::Detector::NPlusOneQuery.call_association(owner, refl.name)
181
- association = owner.association refl.name
182
- Array.wrap(association.target).each do |through_record|
183
- Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
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
- Bullet::Detector::NPlusOneQuery.call_association(owner, reflection.through_reflection.name)
154
- association = owner.association reflection.through_reflection.name
155
- Array.wrap(association.target).each do |through_record|
156
- Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
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
- Array.wrap(association.target).each do |through_record|
183
- Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
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
- Array.wrap(association.target).each do |through_record|
183
- Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
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
- Array.wrap(association.target).each do |through_record|
186
- Bullet::Detector::NPlusOneQuery.call_association(through_record, source_reflection.name)
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
@@ -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
- def first(opts = {})
14
- result = origin_first(opts)
15
- Bullet::Detector::NPlusOneQuery.add_impossible_object(result) if result
16
- result
17
- end
18
-
19
- def last(opts = {})
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bullet
4
- VERSION = '7.0.3'
4
+ VERSION = '7.0.4'
5
5
  end
@@ -474,7 +474,15 @@ if active_record?
474
474
  end
475
475
 
476
476
  it 'should detect preload associations' do
477
- Firm.includes(:clients).each { |firm| firm.clients.map(&:name) }
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.3
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-08-13 00:00:00.000000000 Z
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.7
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.