class N1Finder::Query
Query
representation
Constants
- ID
Regular expression to find numeric ids in queries and in params
- UUID
Regular expression to find UUIDs in queries and in params
Attributes
backtrace[R]
@!attribute [r] query
Original query string combined with params
@!attribute [backtrace] line
Backtrace up to function where we cought this query
query[R]
@!attribute [r] query
Original query string combined with params
@!attribute [backtrace] line
Backtrace up to function where we cought this query
Public Class Methods
new(query, params, backtrace)
click to toggle source
@param [String] query @param [Hash] params @param [Array<String>] backtrace
# File lib/n_1_finder/query.rb, line 20 def initialize(query, params, backtrace) @query = self.class.query_with_params(query, params) @backtrace = backtrace end
query_with_params(query, params)
click to toggle source
Combines query and its params to readable format
@param [String] query @param [Hash] params
@return [String]
# File lib/n_1_finder/query.rb, line 41 def self.query_with_params(query, params) params.map do |key, value| value = "'#{value}'" if value.is_a?(String) "#{key} = #{value}" end.unshift(query).join(', ') end
Public Instance Methods
footprint()
click to toggle source
Generates query footprint Footprint consists of
- query with masked ids - line of code where this query was executed
@return [ {query, line} => String ]
# File lib/n_1_finder/query.rb, line 31 def footprint @footprint ||= { query: query_footprint, line: application_line } end
Private Instance Methods
application_line()
click to toggle source
# File lib/n_1_finder/query.rb, line 54 def application_line @application_line ||= backtrace.find { |line| !line.include?('/gems/') } end
query_footprint()
click to toggle source
# File lib/n_1_finder/query.rb, line 50 def query_footprint @query_footprint ||= query.gsub(UUID, '[uuid]').gsub(ID, '[id]') end