Commit 4571649d439bc3213514a37e65201e238d48db1a
1 parent
2e395080
Exists in
master
and in
21 other branches
alias_method_chain is deprecated
Showing
1 changed file
with
13 additions
and
15 deletions
Show diff stats
lib/searchkick/logging.rb
1 | 1 | # based on https://gist.github.com/mnutt/566725 |
2 | 2 | |
3 | 3 | module Searchkick |
4 | - class Query | |
5 | - def execute_search_with_instrumentation | |
4 | + module QueryWithInstrumentation | |
5 | + def execute_search | |
6 | 6 | event = { |
7 | 7 | name: "#{searchkick_klass.name} Search", |
8 | 8 | query: params |
9 | 9 | } |
10 | 10 | ActiveSupport::Notifications.instrument("search.searchkick", event) do |
11 | - execute_search_without_instrumentation | |
11 | + super | |
12 | 12 | end |
13 | 13 | end |
14 | - alias_method_chain :execute_search, :instrumentation | |
15 | 14 | end |
16 | 15 | |
17 | - class Index | |
18 | - def store_with_instrumentation(record) | |
16 | + module IndexWithInstrumentation | |
17 | + def store(record) | |
19 | 18 | event = { |
20 | 19 | name: "#{record.searchkick_klass.name} Store", |
21 | 20 | id: search_id(record) |
22 | 21 | } |
23 | 22 | ActiveSupport::Notifications.instrument("request.searchkick", event) do |
24 | - store_without_instrumentation(record) | |
23 | + super(record) | |
25 | 24 | end |
26 | 25 | end |
27 | - alias_method_chain :store, :instrumentation | |
28 | 26 | |
29 | - def remove_with_instrumentation(record) | |
27 | + | |
28 | + def remove(record) | |
30 | 29 | event = { |
31 | 30 | name: "#{record.searchkick_klass.name} Remove", |
32 | 31 | id: search_id(record) |
33 | 32 | } |
34 | 33 | ActiveSupport::Notifications.instrument("request.searchkick", event) do |
35 | - remove_without_instrumentation(record) | |
34 | + super(record) | |
36 | 35 | end |
37 | 36 | end |
38 | - alias_method_chain :remove, :instrumentation | |
39 | 37 | |
40 | - def import_with_instrumentation(records) | |
38 | + def import(records) | |
41 | 39 | if records.any? |
42 | 40 | event = { |
43 | 41 | name: "#{records.first.searchkick_klass.name} Import", |
44 | 42 | count: records.size |
45 | 43 | } |
46 | 44 | ActiveSupport::Notifications.instrument("request.searchkick", event) do |
47 | - import_without_instrumentation(records) | |
45 | + super(records) | |
48 | 46 | end |
49 | 47 | end |
50 | 48 | end |
51 | - alias_method_chain :import, :instrumentation | |
52 | 49 | end |
53 | 50 | |
54 | 51 | # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/log_subscriber.rb |
... | ... | @@ -131,7 +128,8 @@ module Searchkick |
131 | 128 | end |
132 | 129 | end |
133 | 130 | end |
134 | - | |
131 | +Searchkick::Query.send(:prepend, Searchkick::QueryWithInstrumentation) | |
132 | +Searchkick::Index.send(:prepend, Searchkick::IndexWithInstrumentation) | |
135 | 133 | Searchkick::LogSubscriber.attach_to :searchkick |
136 | 134 | ActiveSupport.on_load(:action_controller) do |
137 | 135 | include Searchkick::ControllerRuntime | ... | ... |