lib/shiba/query_watcher.rb in shiba-0.1.1 vs lib/shiba/query_watcher.rb in shiba-0.1.2
- old
+ new
@@ -2,17 +2,18 @@
require 'json'
require 'rails'
module Shiba
class QueryWatcher
- FINGERPRINTS = {}
IGNORE = /\.rvm|gem|vendor\/|rbenv|seed|db|shiba|test|spec/
def self.watch(file)
new(file).watch
end
+ attr_reader :queries
+
def initialize(file)
@file = file
# fixme mem growth on this is kinda nasty
@queries = {}
end
@@ -21,14 +22,16 @@
def watch
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload|
sql = payload[:sql]
if sql.start_with?("SELECT")
- lines = app_backtrace
- if lines && !@queries[sql]
- @file.puts("#{sql} /*shiba#{lines}*/" )
+ fingerprint = Query.get_fingerprint(sql)
+ if !@queries[fingerprint]
+ if lines = app_backtrace
+ @file.puts("#{sql} /*shiba#{lines}*/")
+ end
end
- @queries[sql] = true
+ @queries[fingerprint] = true
end
end
end
protected