Skip to content

Commit ccdd524

Browse files
authored
Merge pull request rails#52232 from djfpaagman/activejob-lazy-query-source
Improve performance of ActiveJob::LogSubscriber#query_source_location
2 parents 0d30e84 + 912440d commit ccdd524

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

activejob/lib/active_job/log_subscriber.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,29 @@ def error(progname = nil, &block)
189189
end
190190

191191
def log_enqueue_source
192-
source = extract_enqueue_source_location(caller)
192+
source = enqueue_source_location
193193

194194
if source
195195
logger.info("↳ #{source}")
196196
end
197197
end
198198

199-
def extract_enqueue_source_location(locations)
200-
backtrace_cleaner.clean(locations.lazy).first
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
214+
end
201215
end
202216

203217
def enqueued_jobs_message(adapter, enqueued_jobs)

0 commit comments

Comments
 (0)