Skip to content

Commit 9286009

Browse files
committed
Remove conditional Thread.each_caller_location usage
1 parent b050366 commit 9286009

File tree

4 files changed

+24
-63
lines changed

4 files changed

+24
-63
lines changed

actionpack/lib/action_dispatch/routing/mapper.rb

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -375,35 +375,18 @@ def dispatcher(raise_on_name_error)
375375
Routing::RouteSet::Dispatcher.new raise_on_name_error
376376
end
377377

378-
if Thread.respond_to?(:each_caller_location)
379-
def route_source_location
380-
if Mapper.route_source_locations
381-
action_dispatch_dir = File.expand_path("..", __dir__)
382-
Thread.each_caller_location do |location|
383-
next if location.path.start_with?(action_dispatch_dir)
378+
def route_source_location
379+
if Mapper.route_source_locations
380+
action_dispatch_dir = File.expand_path("..", __dir__)
381+
Thread.each_caller_location do |location|
382+
next if location.path.start_with?(action_dispatch_dir)
384383

385-
cleaned_path = Mapper.backtrace_cleaner.clean_frame(location.path)
386-
next if cleaned_path.nil?
384+
cleaned_path = Mapper.backtrace_cleaner.clean_frame(location.path)
385+
next if cleaned_path.nil?
387386

388-
return "#{cleaned_path}:#{location.lineno}"
389-
end
390-
nil
391-
end
392-
end
393-
else
394-
def route_source_location
395-
if Mapper.route_source_locations
396-
action_dispatch_dir = File.expand_path("..", __dir__)
397-
caller_locations.each do |location|
398-
next if location.path.start_with?(action_dispatch_dir)
399-
400-
cleaned_path = Mapper.backtrace_cleaner.clean_frame(location.path)
401-
next if cleaned_path.nil?
402-
403-
return "#{cleaned_path}:#{location.lineno}"
404-
end
405-
nil
387+
return "#{cleaned_path}:#{location.lineno}"
406388
end
389+
nil
407390
end
408391
end
409392
end

activejob/lib/active_job/log_subscriber.rb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,12 @@ def log_enqueue_source
196196
end
197197
end
198198

199-
if Thread.respond_to?(:each_caller_location)
200-
def enqueue_source_location
201-
Thread.each_caller_location do |location|
202-
frame = backtrace_cleaner.clean_frame(location)
203-
return frame if frame
204-
end
205-
nil
206-
end
207-
else
208-
def enqueue_source_location
209-
caller_locations(2).each do |location|
210-
frame = backtrace_cleaner.clean_frame(location)
211-
return frame if frame
212-
end
213-
nil
199+
def enqueue_source_location
200+
Thread.each_caller_location do |location|
201+
frame = backtrace_cleaner.clean_frame(location)
202+
return frame if frame
214203
end
204+
nil
215205
end
216206

217207
def enqueued_jobs_message(adapter, enqueued_jobs)

activerecord/lib/active_record/log_subscriber.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,12 @@ def log_query_source
126126
end
127127
end
128128

129-
if Thread.respond_to?(:each_caller_location)
130-
def query_source_location
131-
Thread.each_caller_location do |location|
132-
frame = backtrace_cleaner.clean_frame(location)
133-
return frame if frame
134-
end
135-
nil
136-
end
137-
else
138-
def query_source_location
139-
backtrace_cleaner.clean(caller(1).lazy).first
129+
def query_source_location
130+
Thread.each_caller_location do |location|
131+
frame = backtrace_cleaner.clean_frame(location)
132+
return frame if frame
140133
end
134+
nil
141135
end
142136

143137
def filter(name, value)

activerecord/lib/active_record/query_logs.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,12 @@ def clear_cache # :nodoc:
152152
self.cached_comment = nil
153153
end
154154

155-
if Thread.respond_to?(:each_caller_location)
156-
def query_source_location # :nodoc:
157-
Thread.each_caller_location do |location|
158-
frame = LogSubscriber.backtrace_cleaner.clean_frame(location.path)
159-
return frame if frame
160-
end
161-
nil
162-
end
163-
else
164-
def query_source_location # :nodoc:
165-
LogSubscriber.backtrace_cleaner.clean(caller_locations(1).each).first
155+
def query_source_location # :nodoc:
156+
Thread.each_caller_location do |location|
157+
frame = LogSubscriber.backtrace_cleaner.clean_frame(location.path)
158+
return frame if frame
166159
end
160+
nil
167161
end
168162

169163
ActiveSupport::ExecutionContext.after_change { ActiveRecord::QueryLogs.clear_cache }

0 commit comments

Comments
 (0)