diff options
author | John Hawthorn <john@hawthorn.email> | 2019-04-14 18:22:43 -0700 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2019-04-15 16:13:06 -0700 |
commit | 0bab6310d623f9f8ed382c93ddeb9f4d1a0b8f75 (patch) | |
tree | 7ec9d96b3c4bcfcc903030b9909b506d80d6f7cc | |
parent | 60afbfffdcdb4510deccf8d6db303dd4260e3dc7 (diff) | |
download | rails-0bab6310d623f9f8ed382c93ddeb9f4d1a0b8f75.tar.gz rails-0bab6310d623f9f8ed382c93ddeb9f4d1a0b8f75.tar.bz2 rails-0bab6310d623f9f8ed382c93ddeb9f4d1a0b8f75.zip |
Find query_source_location using lazy Enumerator
This way, we only need to filter the backtrace up to the first non-noise
stack frame.
This also updates noise to be able to deal with being passed a lazy
enum. We don't need this anywhere, but it seemed better for this to be
consistent.
-rw-r--r-- | activerecord/lib/active_record/log_subscriber.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/backtrace_cleaner.rb | 6 | ||||
-rw-r--r-- | railties/test/backtrace_cleaner_test.rb | 10 |
3 files changed, 16 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index 6b84431343..6248c2f578 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -110,7 +110,7 @@ module ActiveRecord end def extract_query_source_location(locations) - backtrace_cleaner.clean(locations).first + backtrace_cleaner.clean(locations.lazy).first end end end diff --git a/activesupport/lib/active_support/backtrace_cleaner.rb b/activesupport/lib/active_support/backtrace_cleaner.rb index 62973eca58..02cbfbaee6 100644 --- a/activesupport/lib/active_support/backtrace_cleaner.rb +++ b/activesupport/lib/active_support/backtrace_cleaner.rb @@ -122,7 +122,11 @@ module ActiveSupport end def noise(backtrace) - backtrace - silence(backtrace) + backtrace.select do |line| + @silencers.any? do |s| + s.call(line) + end + end end end end diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index ec512b6b64..6de23acebe 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -17,6 +17,16 @@ class BacktraceCleanerTest < ActiveSupport::TestCase 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}'"] |