ar_lazy_preload 0.5.1 → 0.5.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8b1ef234e5a995bfce176e47fe5526fba9330b61cc27374e6667a5f5dfca3af
|
4
|
+
data.tar.gz: 3516b8bf449802b2ba3ff7022faec299ff274fe4716db884e46da63fe47d5ac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80a0a1e05b961a6d66b20c0b5e1a32ee2824d868e7e96d25e85b4e2b3c48baa1ee9129cf934b71e73a2887245faa9f54b3ecc23cc7815d60c30efc8bca9fbb7b
|
7
|
+
data.tar.gz: bbb5f854ed701c562d31f00cf3f832eb668c42aca809e4376aed4b78c114bd3c25db15edea712d65419a23c3fbbe1dfac5d698055dad5c5ae61ea837ea6fa273
|
@@ -28,8 +28,10 @@ module ArLazyPreload
|
|
28
28
|
associated_records = parent_context.records.flat_map do |record|
|
29
29
|
next if record.nil?
|
30
30
|
|
31
|
-
record_association = record.association(association_name)
|
32
31
|
reflection = reflection_cache[record.class]
|
32
|
+
next if reflection.nil?
|
33
|
+
|
34
|
+
record_association = record.association(association_name)
|
33
35
|
reflection.collection? ? record_association.target : record_association.reader
|
34
36
|
end
|
35
37
|
|
@@ -44,7 +44,11 @@ module ArLazyPreload
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def perform_preloading(association_name)
|
47
|
-
|
47
|
+
filtered_records = records.select do |record|
|
48
|
+
reflection_names_cache[record.class].include?(association_name)
|
49
|
+
end
|
50
|
+
preloader.preload(filtered_records, association_name)
|
51
|
+
|
48
52
|
loaded_association_names.add(association_name)
|
49
53
|
|
50
54
|
AssociatedContextBuilder.prepare(
|
@@ -64,6 +68,12 @@ module ArLazyPreload
|
|
64
68
|
def preloader
|
65
69
|
@preloader ||= ActiveRecord::Associations::Preloader.new
|
66
70
|
end
|
71
|
+
|
72
|
+
def reflection_names_cache
|
73
|
+
@reflection_names_cache ||= Hash.new do |hash, klass|
|
74
|
+
hash[klass] = klass.reflect_on_all_associations.map(&:name)
|
75
|
+
end
|
76
|
+
end
|
67
77
|
end
|
68
78
|
end
|
69
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_lazy_preload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|