lib/shiba/query_watcher.rb in shiba-0.2.3 vs lib/shiba/query_watcher.rb in shiba-0.3.0
- old
+ new
@@ -15,17 +15,29 @@
def call(name, start, finish, id, payload)
sql = payload[:sql]
return if !sql.start_with?("SELECT")
+ if sql.include?("$1")
+ sql = interpolate(sql, payload[:type_casted_binds])
+ end
+
+ sql = sql.gsub(/\n/, ' ')
+
fingerprint = Query.get_fingerprint(sql)
return if @queries[fingerprint]
lines = Backtrace.from_app
return if !lines
@file.puts("#{sql} /*shiba#{lines}*/")
@queries[fingerprint] = true
end
+ def interpolate(sql, binds)
+ binds.each_with_index do |val, i|
+ sql = sql.sub("$#{i +1}", ActiveRecord::Base.connection.quote(val))
+ end
+ sql
+ end
end
-end
\ No newline at end of file
+end