Skip to content

Commit 250a724

Browse files
authored
Merge pull request #4506 from amomchilov/replace-each-with-include
Speed up lookup of possible types for Fragments
2 parents 7efd8e6 + e9602f8 commit 250a724

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/graphql/execution/interpreter/runtime.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,8 @@ def gather_selections(owner_object, owner_type, selections, selections_to_run =
343343
if node.type
344344
type_defn = schema.get_type(node.type.name, context)
345345

346-
# Faster than .map{}.include?()
347-
query.warden.possible_types(type_defn).each do |t|
348-
if t == owner_type
349-
gather_selections(owner_object, owner_type, node.selections, selections_to_run, next_selections)
350-
break
351-
end
346+
if query.warden.possible_types(type_defn).include?(owner_type)
347+
gather_selections(owner_object, owner_type, node.selections, selections_to_run, next_selections)
352348
end
353349
else
354350
# it's an untyped fragment, definitely continue
@@ -357,12 +353,8 @@ def gather_selections(owner_object, owner_type, selections, selections_to_run =
357353
when GraphQL::Language::Nodes::FragmentSpread
358354
fragment_def = query.fragments[node.name]
359355
type_defn = query.get_type(fragment_def.type.name)
360-
possible_types = query.warden.possible_types(type_defn)
361-
possible_types.each do |t|
362-
if t == owner_type
363-
gather_selections(owner_object, owner_type, fragment_def.selections, selections_to_run, next_selections)
364-
break
365-
end
356+
if query.warden.possible_types(type_defn).include?(owner_type)
357+
gather_selections(owner_object, owner_type, fragment_def.selections, selections_to_run, next_selections)
366358
end
367359
else
368360
raise "Invariant: unexpected selection class: #{node.class}"

0 commit comments

Comments
 (0)