Module: Searchkick::IndexWithInstrumentation

Included in:
Index
Defined in:
lib/searchkick/logging.rb

Instance Method Summary collapse

Instance Method Details

#bulk_delete(records) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/searchkick/logging.rb', line 97

def bulk_delete(records)
  if records.any?
    event = {
      name: "#{records.first.searchkick_klass.name} Delete",
      count: records.size
    }
    event[:id] = search_id(records.first) if records.size == 1
    if Searchkick.callbacks_value == :bulk
      super
    else
      ActiveSupport::Notifications.instrument("request.searchkick", event) do
        super
      end
    end
  end
end

#bulk_index(records) ⇒ Object Also known as: import



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/searchkick/logging.rb', line 62

def bulk_index(records)
  if records.any?
    event = {
      name: "#{records.first.searchkick_klass.name} Import",
      count: records.size
    }
    event[:id] = search_id(records.first) if records.size == 1
    if Searchkick.callbacks_value == :bulk
      super
    else
      ActiveSupport::Notifications.instrument("request.searchkick", event) do
        super
      end
    end
  end
end

#bulk_update(records, *args) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/searchkick/logging.rb', line 80

def bulk_update(records, *args)
  if records.any?
    event = {
      name: "#{records.first.searchkick_klass.name} Update",
      count: records.size
    }
    event[:id] = search_id(records.first) if records.size == 1
    if Searchkick.callbacks_value == :bulk
      super
    else
      ActiveSupport::Notifications.instrument("request.searchkick", event) do
        super
      end
    end
  end
end

#remove(record) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/searchkick/logging.rb', line 33

def remove(record)
  name = record && record.searchkick_klass ? "#{record.searchkick_klass.name} Remove" : "Remove"
  event = {
    name: name,
    id: search_id(record)
  }
  if Searchkick.callbacks_value == :bulk
    super
  else
    ActiveSupport::Notifications.instrument("request.searchkick", event) do
      super
    end
  end
end

#store(record) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/searchkick/logging.rb', line 19

def store(record)
  event = {
    name: "#{record.searchkick_klass.name} Store",
    id: search_id(record)
  }
  if Searchkick.callbacks_value == :bulk
    super
  else
    ActiveSupport::Notifications.instrument("request.searchkick", event) do
      super
    end
  end
end

#update_record(record, method_name) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/searchkick/logging.rb', line 48

def update_record(record, method_name)
  event = {
    name: "#{record.searchkick_klass.name} Update",
    id: search_id(record)
  }
  if Searchkick.callbacks_value == :bulk
    super
  else
    ActiveSupport::Notifications.instrument("request.searchkick", event) do
      super
    end
  end
end