predictive_load 0.4.1 → 0.4.2
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/lib/predictive_load/loader.rb +13 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 580ba2c90f13384b9fba7ea3c386fbc8c25f79a35dbed9fa1ea3a59aadc2e854
|
4
|
+
data.tar.gz: 79a274f1f22adb3bec3a795c55dde8a01ed29056433e5316ad8d72dd605232f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
72
|
+
ActiveRecord::Associations::Preloader.new(rs, [ association_name ]).run
|
62
73
|
else
|
63
|
-
ActiveRecord::Associations::Preloader.new.preload(
|
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.
|
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:
|
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.
|
179
|
+
rubygems_version: 2.7.6
|
180
180
|
signing_key:
|
181
181
|
specification_version: 4
|
182
182
|
summary: ''
|