Skip to content

Commit ea1c8d9

Browse files
authored
Merge pull request github-community-projects#57 from github/fewer-backtrace-allocations
Reduce allocations due to collocation enforcement
2 parents c6d60e1 + 3808c05 commit ea1c8d9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/graphql/client/collocated_enforcement.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def enforce_collocated_callers(mod, methods, path)
2929
define_method(method) do |*args, &block|
3030
return super(*args, &block) if Thread.current[:query_result_caller_location_ignore]
3131

32-
locations = caller_locations(1)
32+
locations = caller_locations(1, 1)
3333
if locations.first.path != path
3434
error = NonCollocatedCallerError.new("#{method} was called outside of '#{path}' https://git.io/v1syX")
35-
error.set_backtrace(locations.map(&:to_s))
35+
error.set_backtrace(caller(1))
3636
raise error
3737
end
3838

test/test_collocated_enforcement.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,16 @@ def test_enforce_collocated_callers
5656
format_person_info_via_send(person)
5757
end
5858
end
59+
60+
def test_exception_backtrace_excludes_enforce_collocated_callers
61+
person = Person.new
62+
begin
63+
format_person_info(person)
64+
rescue GraphQL::Client::NonCollocatedCallerError => e
65+
exception = e
66+
end
67+
68+
assert_includes exception.backtrace[0], "in `format_person_info'"
69+
assert_includes exception.backtrace[1], "in `test_exception_backtrace_excludes_enforce_collocated_callers'"
70+
end
5971
end

0 commit comments

Comments
 (0)