graphiti 1.0.alpha.12 → 1.0.alpha.14
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5ea1fc71cafab76e9d9978a65d0db8c9e947609
|
4
|
+
data.tar.gz: f09f4fbb1322c7da9a07c9ba0e96d9906a586b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf4c9ddbd38979ec78ee272629304cc725a9ab2f634e8864f3cd146b9101a2b704ac55299033360fe92a1153a79e963f199256a2306ff60bd2b418fa50325509
|
7
|
+
data.tar.gz: c42eb4d69df9c79c9bf54b1fb71bf71c6c531ce687c84fa5967a9bc0e736fb1a2130ad364ffca4aeb9f02da3ed42dd406413db514f97b13a6bfa2b8bfce874b2
|
data/lib/graphiti/sideload.rb
CHANGED
@@ -166,18 +166,28 @@ module Graphiti
|
|
166
166
|
end
|
167
167
|
|
168
168
|
def assign(parents, children)
|
169
|
-
|
169
|
+
track_associated = type == :has_one
|
170
|
+
associated = [] if track_associated
|
171
|
+
if performant_assign?
|
172
|
+
map = child_map(children)
|
173
|
+
end
|
174
|
+
|
170
175
|
parents.each do |parent|
|
171
|
-
|
176
|
+
if performant_assign?
|
177
|
+
relevant_children = children_for(parent, map) || []
|
178
|
+
else
|
179
|
+
relevant_children = fire_assign_each(parent, children)
|
180
|
+
end
|
181
|
+
|
172
182
|
if relevant_children.is_a?(Array)
|
173
|
-
|
174
|
-
|
183
|
+
associated |= relevant_children if track_associated
|
184
|
+
associate_all(parent, relevant_children)
|
175
185
|
else
|
176
|
-
associated << relevant_children if relevant_children
|
186
|
+
associated << relevant_children if track_associated && relevant_children
|
177
187
|
associate(parent, relevant_children)
|
178
188
|
end
|
179
189
|
end
|
180
|
-
children.replace(associated)
|
190
|
+
children.replace(associated) if track_associated
|
181
191
|
end
|
182
192
|
|
183
193
|
def resolve(parents, query)
|
@@ -246,6 +256,10 @@ module Graphiti
|
|
246
256
|
parent_ids
|
247
257
|
end
|
248
258
|
|
259
|
+
def performant_assign?
|
260
|
+
!self.class.assign_each_proc
|
261
|
+
end
|
262
|
+
|
249
263
|
private
|
250
264
|
|
251
265
|
def load_options(parents, query)
|
@@ -23,11 +23,6 @@ class Graphiti::Sideload::BelongsTo < Graphiti::Sideload
|
|
23
23
|
{ primary_key => parent_ids.join(',') }
|
24
24
|
end
|
25
25
|
|
26
|
-
def assign_each(parent, children)
|
27
|
-
children_hash = children.index_by(&primary_key)
|
28
|
-
children_hash[parent.send(foreign_key)]
|
29
|
-
end
|
30
|
-
|
31
26
|
def ids_for_parents(parents)
|
32
27
|
parent_ids = parents.map(&foreign_key)
|
33
28
|
parent_ids.compact!
|
@@ -45,4 +40,14 @@ class Graphiti::Sideload::BelongsTo < Graphiti::Sideload
|
|
45
40
|
:"#{model_name.underscore}_id"
|
46
41
|
end
|
47
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def child_map(children)
|
47
|
+
children.index_by(&primary_key)
|
48
|
+
end
|
49
|
+
|
50
|
+
def children_for(parent, map)
|
51
|
+
map[parent.send(foreign_key)]
|
52
|
+
end
|
48
53
|
end
|
@@ -14,8 +14,13 @@ class Graphiti::Sideload::HasMany < Graphiti::Sideload
|
|
14
14
|
{ foreign_key => ids_for_parents(parents).join(',') }
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
private
|
18
|
+
|
19
|
+
def child_map(children)
|
20
|
+
children.group_by(&foreign_key)
|
21
|
+
end
|
22
|
+
|
23
|
+
def children_for(parent, map)
|
24
|
+
map[parent.send(primary_key)] || []
|
20
25
|
end
|
21
26
|
end
|
@@ -3,9 +3,9 @@ class Graphiti::Sideload::HasOne < Graphiti::Sideload::HasMany
|
|
3
3
|
:has_one
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
private
|
7
|
+
|
8
|
+
def children_for(parent, map)
|
9
|
+
super[0]
|
10
10
|
end
|
11
11
|
end
|
@@ -19,6 +19,10 @@ class Graphiti::Sideload::ManyToMany < Graphiti::Sideload::HasMany
|
|
19
19
|
raise 'You must explicitly pass :foreign_key for many-to-many relationships, or override in subclass to return a hash.'
|
20
20
|
end
|
21
21
|
|
22
|
+
def performant_assign?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
22
26
|
def assign_each(parent, children)
|
23
27
|
children.select do |c|
|
24
28
|
match = ->(ct) { ct.send(true_foreign_key) == parent.send(primary_key) }
|
data/lib/graphiti/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.alpha.
|
4
|
+
version: 1.0.alpha.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|