busload 0.1.0 → 0.1.1
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 +4 -0
- data/README.md +5 -5
- data/lib/busload/load/cte.rb +2 -1
- data/lib/busload/load.rb +0 -7
- 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: '09d9798877116d2186960b5c766122a951901fd3227aeb313b75c65a1d0d5a53'
|
|
4
|
+
data.tar.gz: 7263aa5982b548da1edbb75e614e21b0004af69a945a0c02a10f719b1a525ef1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b07591f0b447d971a07ed5fbc3e9acf68ac98c82f1b51063f343de42aafd1a1ee0defdd624b8ad6a38dc4c30cffc1105190d2bf615dcec0673f576d6a13c299
|
|
7
|
+
data.tar.gz: 90f1bdd069f47353df473590ab044c98526bed448d4924bf7982eb774d21106c10e6d8f9e64b021c365db95cc1e86517822b8eb39d09fa35f2a99b297a5b5dd4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -37,19 +37,19 @@ WITH
|
|
|
37
37
|
WHERE active
|
|
38
38
|
ORDER BY name
|
|
39
39
|
),
|
|
40
|
-
"
|
|
40
|
+
"busload_0_1" AS (
|
|
41
41
|
SELECT posts.*
|
|
42
42
|
FROM posts
|
|
43
43
|
WHERE user_id IN (SELECT id FROM "busload_0")
|
|
44
44
|
),
|
|
45
|
-
"
|
|
45
|
+
"busload_0_1_1" AS (
|
|
46
46
|
SELECT comments.*
|
|
47
47
|
FROM comments
|
|
48
|
-
WHERE post_id IN (SELECT id FROM "
|
|
48
|
+
WHERE post_id IN (SELECT id FROM "busload_0_1")
|
|
49
49
|
)
|
|
50
50
|
SELECT 0, t::text FROM "busload_0" t
|
|
51
|
-
UNION ALL SELECT 1, t::text FROM "
|
|
52
|
-
UNION ALL SELECT 2, t::text FROM "
|
|
51
|
+
UNION ALL SELECT 1, t::text FROM "busload_0_1" t
|
|
52
|
+
UNION ALL SELECT 2, t::text FROM "busload_0_1_1" t
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
Works on associations too:
|
data/lib/busload/load/cte.rb
CHANGED
|
@@ -18,6 +18,7 @@ module Busload
|
|
|
18
18
|
@owner = owner
|
|
19
19
|
@association = association
|
|
20
20
|
@preloader = preloader
|
|
21
|
+
@children = 0
|
|
21
22
|
@sql = @relation.to_sql
|
|
22
23
|
@join_dependency = join_dependency if @relation.eager_loading?
|
|
23
24
|
end
|
|
@@ -37,7 +38,7 @@ module Busload
|
|
|
37
38
|
def cte_for(association)
|
|
38
39
|
table = Arel::Table.new(name)
|
|
39
40
|
relation = association.relation_for(table.project(table[association.reflection.join_foreign_key]))
|
|
40
|
-
CTE.new(relation, "#{name}
|
|
41
|
+
CTE.new(relation, "#{name}_#{@children += 1}", owner: self, association:)
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def load(result)
|
data/lib/busload/load.rb
CHANGED
|
@@ -33,7 +33,6 @@ module Busload
|
|
|
33
33
|
|
|
34
34
|
def run
|
|
35
35
|
@ctes.first.model.with_connection do |connection|
|
|
36
|
-
ensure_names_fit(connection)
|
|
37
36
|
results = Adapters.for(connection).select_all(@ctes.to_h { |cte| [cte.name, cte.sql] })
|
|
38
37
|
@ctes.zip(results) { |cte, result| cte.load(result) }
|
|
39
38
|
end
|
|
@@ -74,12 +73,6 @@ module Busload
|
|
|
74
73
|
end
|
|
75
74
|
end
|
|
76
75
|
|
|
77
|
-
# Databases cut off long names, which could make two CTEs share one.
|
|
78
|
-
def ensure_names_fit(connection)
|
|
79
|
-
too_long = @ctes.find { |cte| cte.name.bytesize > connection.max_identifier_length }
|
|
80
|
-
raise Error, "Busload's CTE name #{too_long.name} is too long; preload fewer levels deep" if too_long
|
|
81
|
-
end
|
|
82
|
-
|
|
83
76
|
# Includes that become a JOIN load with the relation, not as preloads.
|
|
84
77
|
def preloads_for(relation)
|
|
85
78
|
return [] if relation.skip_preloading_value
|
data/lib/busload/version.rb
CHANGED