Commit 76c340aa authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'simplify-es-maintenance-callbacks' into 'master'

Simplify elasticsearch maintenance callbacks

See merge request gitlab-org/gitlab!24895
parents 96850c5c f2d21bea
......@@ -34,38 +34,38 @@ module Elastic
Elasticsearch::Model::Registry.add(self) if self.is_a?(Class)
if self < ActiveRecord::Base
after_commit on: :create do
if Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
ElasticIndexerWorker.perform_async(:index, self.class.to_s, self.id, self.es_id)
end
end
after_commit on: :update do
if Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
ElasticIndexerWorker.perform_async(
:update,
self.class.to_s,
self.id,
self.es_id,
changed_fields: self.previous_changes.keys
)
end
end
after_commit on: :destroy do
if Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
ElasticIndexerWorker.perform_async(
:delete,
self.class.to_s,
self.id,
self.es_id,
es_parent: self.es_parent
)
end
end
after_commit :maintain_elasticsearch_create, on: :create
after_commit :maintain_elasticsearch_update, on: :update
after_commit :maintain_elasticsearch_destroy, on: :destroy
end
end
def maintain_elasticsearch_create
return unless Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
ElasticIndexerWorker.perform_async(:index, self.class.to_s, self.id, self.es_id)
end
def maintain_elasticsearch_update
return unless Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
ElasticIndexerWorker.perform_async(
:update,
self.class.to_s,
self.id,
self.es_id,
changed_fields: self.previous_changes.keys
)
end
def maintain_elasticsearch_destroy
return unless Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
ElasticIndexerWorker.perform_async(
:delete, self.class.to_s, self.id, self.es_id, es_parent: self.es_parent
)
end
class_methods do
def __elasticsearch__
@__elasticsearch__ ||= ::Elastic::MultiVersionClassProxy.new(self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment