Skip to content

Commit

Permalink
Merge pull request #5037 from rmosolgo/compare-by-identity-cleanup
Browse files Browse the repository at this point in the history
Clean up compare-by-identity usage
  • Loading branch information
rmosolgo authored Jul 23, 2024
2 parents 1a52cad + 9b5e4d3 commit a502b6a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 25 deletions.
15 changes: 5 additions & 10 deletions lib/graphql/execution/interpreter/arguments_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,17 @@ def initialize(query)
@query = query
@dataloader = query.context.dataloader
@storage = Hash.new do |h, argument_owner|
args_by_parent = if argument_owner.arguments_statically_coercible?
h[argument_owner] = if argument_owner.arguments_statically_coercible?
shared_values_cache = {}
Hash.new do |h2, ignored_parent_object|
h2[ignored_parent_object] = shared_values_cache
end
end.compare_by_identity
else
Hash.new do |h2, parent_object|
args_by_node = {}
args_by_node.compare_by_identity
h2[parent_object] = args_by_node
end
h2[parent_object] = {}.compare_by_identity
end.compare_by_identity
end
args_by_parent.compare_by_identity
h[argument_owner] = args_by_parent
end
@storage.compare_by_identity
end.compare_by_identity
end

def fetch(ast_node, argument_owner, parent_object)
Expand Down
10 changes: 2 additions & 8 deletions lib/graphql/execution/interpreter/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def initialize(query:, lazies_at_depth:)
end
end
# { Class => Boolean }
@lazy_cache = {}
@lazy_cache.compare_by_identity
@lazy_cache = {}.compare_by_identity
end

def final_result
Expand Down Expand Up @@ -727,12 +726,7 @@ def directives_include?(node, graphql_object, parent_type)
end

def get_current_runtime_state
current_state = Thread.current[:__graphql_runtime_info] ||= begin
per_query_state = {}
per_query_state.compare_by_identity
per_query_state
end

current_state = Thread.current[:__graphql_runtime_info] ||= {}.compare_by_identity
current_state[@query] ||= CurrentState.new
end

Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ def own_types
end

def own_references_to
@own_references_to ||= {}.tap(&:compare_by_identity)
@own_references_to ||= {}.compare_by_identity
end

def non_introspection_types
Expand All @@ -1517,7 +1517,7 @@ def own_orphan_types
end

def own_possible_types
@own_possible_types ||= {}.tap(&:compare_by_identity)
@own_possible_types ||= {}.compare_by_identity
end

def own_union_memberships
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/schema/introspection_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(schema)
load_constant(:DirectiveLocationEnum)
]
@types = {}
@possible_types = {}.tap(&:compare_by_identity)
@possible_types = {}.compare_by_identity
type_defns.each do |t|
@types[t.graphql_name] = t
@possible_types[t] = [t]
Expand Down
5 changes: 1 addition & 4 deletions lib/graphql/schema/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def initialize(context:, schema:)
@subscription = @schema.subscription
@context = context
@visibility_cache = read_through { |m| schema.visible?(m, context) }
@visibility_cache.compare_by_identity
# Initialize all ivars to improve object shape consistency:
@types = @visible_types = @reachable_types = @visible_parent_fields =
@visible_possible_types = @visible_fields = @visible_arguments = @visible_enum_arrays =
Expand Down Expand Up @@ -463,9 +462,7 @@ def visible?(member)
end

def read_through
h = Hash.new { |h, k| h[k] = yield(k) }
h.compare_by_identity
h
Hash.new { |h, k| h[k] = yield(k) }.compare_by_identity
end

def reachable_type_set
Expand Down

0 comments on commit a502b6a

Please sign in to comment.