busload 0.1.1 → 0.1.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -0
- data/lib/busload/preloader/association.rb +10 -1
- data/lib/busload/preloader.rb +18 -18
- data/lib/busload/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e1048e2f379939ede513cb17721d78c590ff26d03aa6f20209c0310c7a2f4f1f
|
|
4
|
+
data.tar.gz: 54ce60b221db91fb6e04ab404ced358415f002aaf8fa6fdb01e10a81f0298b41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1460415af42d0a255b59ce98d3edf7ec994b89814a67f8f209bee5a6665bf095222cbf272e98c891926aff735dab792892772e5f907e81de6d3936f10e7a156
|
|
7
|
+
data.tar.gz: 25d5d61d874119f7efdeb7a68384986686cf7985b49e902d8754c681c61eeb2676f19cd12d52cec7878f33693010933d051792dd2e8ef5fcd3faac77838b2549
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.1.2] - 2026-12-01
|
|
4
|
+
|
|
5
|
+
- Fixed error for associations whose key column types differ
|
|
6
|
+
- Fixed `Busload::Preloader` skipping nested preloads under associations already loaded
|
|
7
|
+
|
|
3
8
|
## [0.1.1] - 2026-11-30
|
|
4
9
|
|
|
5
10
|
- Fixed error for deeply nested or long-named preloads
|
data/README.md
CHANGED
|
@@ -109,6 +109,7 @@ These preloads load afterwards, with Active Record as usual. Busload logs why at
|
|
|
109
109
|
- associations through other associations
|
|
110
110
|
- scopes that take the owner as an argument
|
|
111
111
|
- composite keys
|
|
112
|
+
- keys whose column types differ, like a `uuid` id and a `varchar` foreign key
|
|
112
113
|
- preloads under a relation that's eager loaded or has a custom `select`
|
|
113
114
|
|
|
114
115
|
### Bulk writes
|
|
@@ -20,7 +20,7 @@ module Busload
|
|
|
20
20
|
elsif reflection.polymorphic? then "it's polymorphic"
|
|
21
21
|
elsif reflection.through_reflection? then "it goes through another association"
|
|
22
22
|
elsif reflection.scope&.arity.to_i.positive? then "its scope depends on the owner"
|
|
23
|
-
|
|
23
|
+
else key_reason
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -46,6 +46,15 @@ module Busload
|
|
|
46
46
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
|
+
def key_reason
|
|
50
|
+
if reflection.join_foreign_key.is_a?(Array)
|
|
51
|
+
"it has a composite key"
|
|
52
|
+
elsif @model.columns_hash[reflection.join_foreign_key]&.sql_type !=
|
|
53
|
+
reflection.klass.columns_hash[reflection.join_primary_key]&.sql_type
|
|
54
|
+
"its key types don't match"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
49
58
|
# Styled like the names on Active Record's SQL log lines.
|
|
50
59
|
def log_name
|
|
51
60
|
ActiveSupport::LogSubscriber.colorize_logging ? "\e[1m\e[36mBusload\e[0m" : "Busload"
|
data/lib/busload/preloader.rb
CHANGED
|
@@ -26,8 +26,9 @@ module Busload
|
|
|
26
26
|
return active_record_preloader(records, associations).call unless busloadable?
|
|
27
27
|
return [] if empty?
|
|
28
28
|
|
|
29
|
-
roots =
|
|
30
|
-
|
|
29
|
+
@roots = []
|
|
30
|
+
plan(records, associations)
|
|
31
|
+
Load.new(@roots).run if @roots.any?
|
|
31
32
|
[]
|
|
32
33
|
end
|
|
33
34
|
|
|
@@ -37,35 +38,34 @@ module Busload
|
|
|
37
38
|
scope.nil? && @available_records.empty? && associate_by_default
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
records.group_by(&:class).flat_map do |model, owners|
|
|
44
|
-
preloads.filter_map { |name, nested| plan_preload(model, owners, name, nested) }
|
|
41
|
+
def plan(records, associations)
|
|
42
|
+
records.group_by(&:class).each do |model, owners|
|
|
43
|
+
preloads(associations).each { |name, nested| plan_preload(model, owners, name, nested) }
|
|
45
44
|
end
|
|
46
45
|
end
|
|
47
46
|
|
|
48
47
|
def plan_preload(model, owners, name, nested)
|
|
49
48
|
association = Association.new(model, name)
|
|
50
|
-
|
|
51
|
-
association.log_loads_separately(reason)
|
|
52
|
-
active_record_preloader(owners, name => nested).call
|
|
53
|
-
return
|
|
54
|
-
end
|
|
49
|
+
return load_separately(association, owners, name, nested) if association.reason
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
loaded, unloaded = owners.partition { |owner| owner.association(name).loaded? }
|
|
52
|
+
plan(loaded.flat_map { |owner| Array(owner.association(name).target) }, nested)
|
|
53
|
+
@roots << root_for(association, unloaded, nested) if unloaded.any?
|
|
54
|
+
end
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
def load_separately(association, owners, name, nested)
|
|
57
|
+
association.log_loads_separately(association.reason)
|
|
58
|
+
active_record_preloader(owners, name => nested).call
|
|
60
59
|
end
|
|
61
60
|
|
|
62
|
-
def
|
|
61
|
+
def root_for(association, owners, nested)
|
|
63
62
|
keys = owners.filter_map { |owner| owner[association.reflection.join_foreign_key] }.uniq
|
|
64
63
|
relation = association.relation_for(keys)
|
|
65
|
-
|
|
64
|
+
relation = relation.preload(nested) if nested.any?
|
|
65
|
+
Load::Root.new(relation:, preloader: association.preloader(owners))
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
def preloads
|
|
68
|
+
def preloads(associations)
|
|
69
69
|
flatten(associations).group_by(&:first).map do |name, same|
|
|
70
70
|
[name, same.filter_map(&:last)]
|
|
71
71
|
end
|
data/lib/busload/version.rb
CHANGED