Sha256: d6e8fb39161062fb9effb28c1a126c8ee4859b13ee431d83480a44c2923581bc

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

module ActiveRecord
  module SqlAnalyzer
    module Monkeypatches
      module Query
        def execute(sql, *args)
          return super unless SqlAnalyzer.config

          safe_sql = nil

          SqlAnalyzer.config[:analyzers].each do |analyzer|
            if SqlAnalyzer.config[:should_log_sample_proc].call(analyzer[:name])
              # This is here rather than above intentionally.
              # We assume we're not going to be analyzing 100% of queries and want to only re-encode
              # when it's actually relevant.
              safe_sql ||= sql.encode(Encoding::UTF_8, invalid: :replace, undef: :replace)

              if safe_sql =~ analyzer[:table_regex]
                SqlAnalyzer.background_processor << {
                  sql: safe_sql,
                  caller: caller,
                  logger: analyzer[:logger_instance],
                  tag: Thread.current[:_ar_analyzer_tag],
                  request_path: Thread.current[:_ar_analyzer_request_path]
                }
              end
            end
          end

          super
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_record-sql_analyzer-0.0.8 lib/active_record/sql_analyzer/monkeypatches/query.rb
active_record-sql_analyzer-0.0.7 lib/active_record/sql_analyzer/monkeypatches/query.rb
active_record-sql_analyzer-0.0.6 lib/active_record/sql_analyzer/monkeypatches/query.rb
active_record-sql_analyzer-0.0.5 lib/active_record/sql_analyzer/monkeypatches/query.rb