Skip to content

Commit

Permalink
Merge pull request #35985 from jhawthorn/lazy_backtrace_clean
Browse files Browse the repository at this point in the history
Find query_source_location using lazy Enumerator
  • Loading branch information
kaspth committed Apr 16, 2019
2 parents 96851dc + 0bab631 commit f87d518
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/log_subscriber.rb
Expand Up @@ -110,7 +110,7 @@ def log_query_source
end

def extract_query_source_location(locations)
backtrace_cleaner.clean(locations).first
backtrace_cleaner.clean(locations.lazy).first
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion activesupport/lib/active_support/backtrace_cleaner.rb
Expand Up @@ -122,7 +122,11 @@ def silence(backtrace)
end

def noise(backtrace)
backtrace - silence(backtrace)
backtrace.select do |line|
@silencers.any? do |s|
s.call(line)
end
end
end
end
end
10 changes: 10 additions & 0 deletions railties/test/backtrace_cleaner_test.rb
Expand Up @@ -17,6 +17,16 @@ def setup
assert_equal 1, result.length
end

test "can filter for noise" do
backtrace = [ "(irb):1",
"/Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'",
"bin/rails:4:in `<main>'" ]
result = @cleaner.clean(backtrace, :noise)
assert_equal "/Path/to/rails/railties/lib/rails/commands/console.rb:77:in `start'", result[0]
assert_equal "bin/rails:4:in `<main>'", result[1]
assert_equal 2, result.length
end

test "should omit ActionView template methods names" do
method_name = ActionView::Template.new(nil, "app/views/application/index.html.erb", nil, locals: []).send :method_name
backtrace = [ "app/views/application/index.html.erb:4:in `block in #{method_name}'"]
Expand Down

0 comments on commit f87d518

Please sign in to comment.