Commit b7298802b37eb5cf4c77962b7104d8d9e839901b
1 parent
8d33e220
Exists in
master
and in
21 other branches
Added process action hook
Showing
1 changed file
with
12 additions
and
2 deletions
Show diff stats
lib/searchkick/logging.rb
... | ... | @@ -15,6 +15,7 @@ module Searchkick |
15 | 15 | alias_method_chain :execute, :instrumentation |
16 | 16 | end |
17 | 17 | |
18 | + # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/log_subscriber.rb | |
18 | 19 | class LogSubscriber < ActiveSupport::LogSubscriber |
19 | 20 | def self.runtime=(value) |
20 | 21 | Thread.current[:searchkick_runtime] = value |
... | ... | @@ -43,11 +44,22 @@ module Searchkick |
43 | 44 | end |
44 | 45 | end |
45 | 46 | |
47 | + # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/railties/controller_runtime.rb | |
46 | 48 | module ControllerRuntime |
47 | 49 | extend ActiveSupport::Concern |
48 | 50 | |
51 | + protected | |
52 | + | |
49 | 53 | attr_internal :searchkick_runtime |
50 | 54 | |
55 | + def process_action(action, *args) | |
56 | + # We also need to reset the runtime before each action | |
57 | + # because of queries in middleware or in cases we are streaming | |
58 | + # and it won't be cleaned up by the method below. | |
59 | + Searchkick::LogSubscriber.reset_runtime | |
60 | + super | |
61 | + end | |
62 | + | |
51 | 63 | def cleanup_view_runtime |
52 | 64 | searchkick_rt_before_render = Searchkick::LogSubscriber.reset_runtime |
53 | 65 | runtime = super |
... | ... | @@ -56,8 +68,6 @@ module Searchkick |
56 | 68 | runtime - searchkick_rt_after_render |
57 | 69 | end |
58 | 70 | |
59 | - protected | |
60 | - | |
61 | 71 | def append_info_to_payload(payload) |
62 | 72 | super |
63 | 73 | payload[:searchkick_runtime] = (searchkick_runtime || 0) + Searchkick::LogSubscriber.reset_runtime | ... | ... |