Skip to content

Commit

Permalink
Merge pull request #2 from packrat386/fix_insert
Browse files Browse the repository at this point in the history
Use dup instead of pre-populating hash
  • Loading branch information
jeffmiller00 committed May 24, 2016
2 parents 67f4e8d + 26afbba commit fff44a1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
9 changes: 0 additions & 9 deletions lib/active_record_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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
4 changes: 2 additions & 2 deletions lib/active_record_stats/rack_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/active_record_stats/resque_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/active_record_stats/sidekiq_server_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/active_record_stats/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveRecordStats
VERSION = "0.1.2"
VERSION = "0.1.3"
end

0 comments on commit fff44a1

Please sign in to comment.