Find source of queries

(cherry picked from commit 458392ef0d334173f65eac41eb23345e3201a024)
This commit is contained in:
James Mason 2018-01-18 17:43:12 -08:00
parent 9908f88570
commit 4a0142f6a6

View file

@ -0,0 +1,17 @@
# http://www.jkfill.com/2015/02/14/log-which-line-caused-a-query/
module LogQuerySource
def debug(*args, &block)
return unless super
backtrace = Rails.backtrace_cleaner.clean caller
relevant_caller_line = backtrace.detect do |caller_line|
!caller_line.include?('/initializers/')
end
if relevant_caller_line
logger.debug("#{ relevant_caller_line.sub("#{ Rails.root }/", '') }")
end
end
end
ActiveRecord::LogSubscriber.send :prepend, LogQuerySource