lib/rorvswild.rb in rorvswild-0.3.4 vs lib/rorvswild.rb in rorvswild-0.3.5

- old
+ new

@@ -12,17 +12,19 @@ def self.detect_config_file return if !defined?(Rails) Rails::Railtie.initializer "rorvswild.detect_config_file" do if !RorVsWild.default_client && (path = Rails.root.join("config/rorvswild.yml")).exist? - RorVsWild.load_config_file(path, Rails.env) + if config = RorVsWild.load_config_file(path)[Rails.env] + RorVsWild::Client.new(config.symbolize_keys) + end end end end - def self.load_config_file(path, environment) - config = YAML.load_file(path)[environment.to_s] and Client.new(config.symbolize_keys) + def self.load_config_file(path) + YAML.load(ERB.new(path.read).result) end def self.register_default_client(client) @default_client = client end @@ -224,23 +226,20 @@ def cleanup_data @data.delete(Thread.current.object_id) end + MEANINGLESS_QUERIES = %w[BEGIN COMMIT].freeze + def push_query(query) - if hash = queries.find { |hash| hash[:line] == query[:line] && hash[:file] == query[:file] } - if query[:runtime] > hash[:max_runtime] - hash[:max_runtime] = query[:runtime] - hash[:plan] = query[:plan] - hash[:sql] = query[:sql] - end - hash[:runtime] += query[:runtime] + hash = queries.find { |hash| hash[:line] == query[:line] && hash[:file] == query[:file] } + queries << hash = {file: query[:file], line: query[:line], runtime: 0, times: 0} if !hash + hash[:runtime] += query[:runtime] + if !MEANINGLESS_QUERIES.include?(query[:sql]) hash[:times] += 1 - else - query[:times] = 1 - query[:max_runtime] = query[:runtime] - queries << query + hash[:sql] ||= query[:sql] + hash[:plan] ||= query[:plan] if query[:plan] end end def slowest_views views.values.sort { |h1, h2| h2[:runtime] <=> h1[:runtime] }[0, 25] @@ -273,14 +272,24 @@ def post_error(hash) post("/errors".freeze, error: hash) end - GEM_HOME_REGEX = ENV["GEM_HOME"] ? /\A#{ENV["GEM_HOME"]}/.freeze : nil + def gem_home + if ENV["GEM_HOME"] && !ENV["GEM_HOME"].empty? + ENV["GEM_HOME"] + elsif ENV["GEM_PATH"] && !(first_gem_path = ENV["GEM_PATH"].split(":").first) + first_gem_path if first_gem_path && !first_gem_path.empty? + end + end + def gem_home_regex + @gem_home_regex ||= gem_home ? /\A#{gem_home}/.freeze : /\/gems\//.freeze + end + def extract_most_relevant_location(stack) - location = stack.find { |str| str =~ app_root_regex && !(str =~ GEM_HOME_REGEX) } if app_root_regex - location ||= stack.find { |str| !(str =~ GEM_HOME_REGEX) } if GEM_HOME_REGEX + location = stack.find { |str| str =~ app_root_regex && !(str =~ gem_home_regex) } if app_root_regex + location ||= stack.find { |str| !(str =~ gem_home_regex) } if gem_home_regex split_file_location(relative_path(location || stack.first)) end def split_file_location(location) file, line, method = location.split(":")