mirror of
https://github.com/samsonjs/grape_logging.git
synced 2026-04-27 14:57:40 +00:00
Merge pull request #7 from marshall-lee/fix_unsubscribing
Fix serious memory leak
This commit is contained in:
commit
6f76458171
1 changed files with 4 additions and 3 deletions
|
|
@ -7,7 +7,7 @@ module GrapeLogging
|
||||||
start_time
|
start_time
|
||||||
|
|
||||||
@db_duration = 0
|
@db_duration = 0
|
||||||
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
|
@subscription = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
|
||||||
event = ActiveSupport::Notifications::Event.new(*args)
|
event = ActiveSupport::Notifications::Event.new(*args)
|
||||||
@db_duration += event.duration
|
@db_duration += event.duration
|
||||||
end if defined?(ActiveRecord)
|
end if defined?(ActiveRecord)
|
||||||
|
|
@ -15,12 +15,13 @@ module GrapeLogging
|
||||||
|
|
||||||
def after
|
def after
|
||||||
stop_time
|
stop_time
|
||||||
logger.info parameters(request, response)
|
logger.info parameters
|
||||||
|
ActiveSupport::Notifications.unsubscribe(@subscription) if @subscription
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def parameters(request, response)
|
def parameters
|
||||||
{
|
{
|
||||||
path: request.path,
|
path: request.path,
|
||||||
params: request.params.to_hash,
|
params: request.params.to_hash,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue