lib/prosopite.rb in prosopite-1.0.5 vs lib/prosopite.rb in prosopite-1.0.6

- old
+ new

@@ -6,23 +6,30 @@ class << self attr_writer :raise, :stderr_logger, :rails_logger, :prosopite_logger, - :allow_list + :allow_stack_paths, + :ignore_queries + def allow_list=(value) + puts "Prosopite.allow_list= is deprecated. Use Prosopite.allow_stack_paths= instead." + + self.allow_stack_paths = value + end + def scan tc[:prosopite_scan] ||= false return if scan? subscribe tc[:prosopite_query_counter] = Hash.new(0) tc[:prosopite_query_holder] = Hash.new { |h, k| h[k] = [] } tc[:prosopite_query_caller] = {} - @allow_list ||= [] + @allow_stack_paths ||= [] tc[:prosopite_scan] = true if block_given? begin @@ -73,12 +80,13 @@ end next unless fingerprints.uniq.size == 1 kaller = tc[:prosopite_query_caller][location_key] + allow_list = (@allow_stack_paths + DEFAULT_ALLOW_LIST) + is_allowed = kaller.any? { |f| allow_list.any? { |s| f.include?(s) } } - is_allowed = kaller.any? { |f| (@allow_list + DEFAULT_ALLOW_LIST).any? { |s| f.include?(s) } } unless is_allowed queries = tc[:prosopite_query_holder][location_key] tc[:prosopite_notifications][queries] = kaller end end @@ -178,17 +186,22 @@ def red(str) str.split("\n").map { |line| "\e[91m#{line}\e[0m" }.join("\n") end + def ignore_query?(sql) + @ignore_queries ||= [] + @ignore_queries.any? { |q| q === sql } + end + def subscribe @subscribed ||= false return if @subscribed ActiveSupport::Notifications.subscribe 'sql.active_record' do |_, _, _, _, data| sql, name = data[:sql], data[:name] - if scan? && name != "SCHEMA" && sql.include?('SELECT') && data[:cached].nil? + if scan? && name != "SCHEMA" && sql.include?('SELECT') && data[:cached].nil? && !ignore_query?(sql) location_key = Digest::SHA1.hexdigest(caller.join) tc[:prosopite_query_counter][location_key] += 1 tc[:prosopite_query_holder][location_key] << sql