diff --git a/lib/active_record_stats.rb b/lib/active_record_stats.rb index 6c7b6f3..c2524b1 100644 --- a/lib/active_record_stats.rb +++ b/lib/active_record_stats.rb @@ -3,9 +3,6 @@ require 'statsd-instrument' module ActiveRecordStats - STATEMENT_KEYS = %w[BEGIN COMMIT DELETE EXPLAIN INSERT - RELEASE ROLLBACK SAVEPOINT SELECT UPDATE WITH].freeze - def self.statement_type(sql) return if sql.nil? @@ -15,10 +12,4 @@ def self.statement_type(sql) type = cleaned.split(' ', 2).first type.try(:upcase) end - - def self.statement_hash - hash = {} - STATEMENT_KEYS.each { |k| hash[k] = 0 } - hash - end end diff --git a/lib/active_record_stats/rack_middleware.rb b/lib/active_record_stats/rack_middleware.rb index ea26203..11bc382 100644 --- a/lib/active_record_stats/rack_middleware.rb +++ b/lib/active_record_stats/rack_middleware.rb @@ -14,7 +14,7 @@ def initialize(app) end def call(env) - totals = ActiveRecordStats.statement_hash + totals = {} db_time = 0 gather_sql = ->(_name, _started_at, _finished_at, _unique_id, payload) { @@ -44,7 +44,7 @@ def call(env) if request_params && controller = request_params['controller'] controller = controller.gsub('/', '__') action = request_params['action'] - emit(controller, action, db_time, totals) + emit(controller, action, db_time, totals.dup) end end diff --git a/lib/active_record_stats/resque_plugin.rb b/lib/active_record_stats/resque_plugin.rb index 78a4ea6..c6a92e5 100644 --- a/lib/active_record_stats/resque_plugin.rb +++ b/lib/active_record_stats/resque_plugin.rb @@ -3,7 +3,7 @@ module ActiveRecordStats module ResquePlugin def around_perform_active_record_stats(*args, &block) - totals = ActiveRecordStats.statement_hash + totals = {} gather_sql = ->(_name, _started_at, _finished_at, _unique_id, payload) { return if payload[:name] == 'SCHEMA' || payload[:sql].blank? @@ -17,7 +17,7 @@ def around_perform_active_record_stats(*args, &block) ensure ActiveSupport::Notifications.unsubscribe(sub) - emit_active_record_stats(name, totals) + emit_active_record_stats(name, totals.dup) end private diff --git a/lib/active_record_stats/sidekiq_server_middleware.rb b/lib/active_record_stats/sidekiq_server_middleware.rb index aecb26c..9e426ba 100644 --- a/lib/active_record_stats/sidekiq_server_middleware.rb +++ b/lib/active_record_stats/sidekiq_server_middleware.rb @@ -3,8 +3,8 @@ module ActiveRecordStats class SidekiqServerMiddleware def call(worker, job, queue) - totals = ActiveRecordStats.statement_hash - + totals = {} + gather_sql = ->(_name, _started_at, _finished_at, _unique_id, payload) { return if payload[:name] == 'SCHEMA' || payload[:sql].blank? return unless type = ActiveRecordStats.statement_type(payload[:sql]) @@ -17,7 +17,7 @@ def call(worker, job, queue) ensure ActiveSupport::Notifications.unsubscribe(sub) - emit(worker.class.to_s, totals) + emit(worker.class.to_s, totals.dup) end private diff --git a/lib/active_record_stats/version.rb b/lib/active_record_stats/version.rb index 6342b31..6e41bbe 100644 --- a/lib/active_record_stats/version.rb +++ b/lib/active_record_stats/version.rb @@ -1,3 +1,3 @@ module ActiveRecordStats - VERSION = "0.1.2" + VERSION = "0.1.3" end