predictive_load 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/predictive_load/loader.rb +13 -2
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 81ada2f7016b7b5509b284c17b4c33de2e954cc4
4
- data.tar.gz: 6eb5283529e87d3cdf5bb8041add35741393ba9f
2
+ SHA256:
3
+ metadata.gz: 580ba2c90f13384b9fba7ea3c386fbc8c25f79a35dbed9fa1ea3a59aadc2e854
4
+ data.tar.gz: 79a274f1f22adb3bec3a795c55dde8a01ed29056433e5316ad8d72dd605232f9
5
5
  SHA512:
6
- metadata.gz: 8b9a33be0b03acd42fd3c59151f2c3fd70baaf4cd9993bcd8e41ef3fad47e6127279a35a5227edb747d0ad9e2fe14b3f7980e673484c6d22b7cd05530f9d71b8
7
- data.tar.gz: 1ec97d78977b7e25082ec45ed327e53dbd6a6bb60e87fcd25e415e7b4ed12fb596e5648124aaf7a27c3c2a8d38a91d11335a2cba4a85fb7d9047bb0dda15954c
6
+ metadata.gz: ec156ee9fea24e8b223f63d31b9f2d000ebb65fcf63005998682097e4ebba3c1c8c19e2df9aadc19819c77c9a90d5a8d01993353215ed61f14aeddcc54a2a20e
7
+ data.tar.gz: 4019f082b0a466304725cb37ad3e0753a19f2fd665bfe699a7221674c2f59be09cdb43db1b84331fe5386388081a529daba414d5d0e8d9b5918c702cba097d2b
@@ -57,10 +57,21 @@ module PredictiveLoad
57
57
  end
58
58
 
59
59
  def preload(association_name)
60
+ # https://github.com/rails/rails/blob/v4.2.10/activerecord/lib/active_record/associations/preloader.rb#L187 (similar to other Rails versions)
61
+ # If the first record association is loaded, Preloader aborts.
62
+ #
63
+ # In a code like `comments.each { |c| c.user }, if the first comment user_id is nil,
64
+ # when calling the method (`user`) ActiveRecord doesn't load the association, but marks it as loaded.
65
+ # So when the second comment calls `user` (and user_id is not nil), @records.first will be the first
66
+ # comment above (with thr association already loaded), which will be checked by Preloader and used to skip
67
+ # any preloading.
68
+ #
69
+ # Fix is pretty simple, ignore any record with association already loaded.
70
+ rs = records_with_association(association_name).reject { |r| r.association(association_name).loaded? }
60
71
  if ActiveRecord::VERSION::STRING <= "4.1.0"
61
- ActiveRecord::Associations::Preloader.new(records_with_association(association_name), [ association_name ]).run
72
+ ActiveRecord::Associations::Preloader.new(rs, [ association_name ]).run
62
73
  else
63
- ActiveRecord::Associations::Preloader.new.preload(records_with_association(association_name), [ association_name ])
74
+ ActiveRecord::Associations::Preloader.new.preload(rs, [ association_name ])
64
75
  end
65
76
  end
66
77
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: predictive_load
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Chapweske
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  version: '0'
177
177
  requirements: []
178
178
  rubyforge_project:
179
- rubygems_version: 2.4.5.1
179
+ rubygems_version: 2.7.6
180
180
  signing_key:
181
181
  specification_version: 4
182
182
  summary: ''