diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2019-04-16 16:04:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-16 16:04:26 +0200 |
commit | f87d518809541d2c89acdb36d5a2a96cab3ab50b (patch) | |
tree | 8056f843c35e0bc759872a97b4e5b780aaef3af0 | |
parent | 96851dcee6a11f3ca48abaa34b1d38bb4766406e (diff) | |
parent | 0bab6310d623f9f8ed382c93ddeb9f4d1a0b8f75 (diff) | |
download | rails-f87d518809541d2c89acdb36d5a2a96cab3ab50b.tar.gz rails-f87d518809541d2c89acdb36d5a2a96cab3ab50b.tar.bz2 rails-f87d518809541d2c89acdb36d5a2a96cab3ab50b.zip |
Merge pull request #35985 from jhawthorn/lazy_backtrace_clean
Find query_source_location using lazy Enumerator
-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}'"] |