Commit 0038f026 authored by Dmitry Gruzd's avatar Dmitry Gruzd Committed by Dylan Griffith

Follow-up refactoring from "Simplify es callbacks"

parent 70918025
...@@ -19,6 +19,10 @@ module Elastic ...@@ -19,6 +19,10 @@ module Elastic
self.project&.use_elasticsearch? self.project&.use_elasticsearch?
end end
def maintaining_elasticsearch?
Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
end
def es_type def es_type
self.class.es_type self.class.es_type
end end
...@@ -34,21 +38,17 @@ module Elastic ...@@ -34,21 +38,17 @@ module Elastic
Elasticsearch::Model::Registry.add(self) if self.is_a?(Class) Elasticsearch::Model::Registry.add(self) if self.is_a?(Class)
if self < ActiveRecord::Base if self < ActiveRecord::Base
after_commit :maintain_elasticsearch_create, on: :create after_commit :maintain_elasticsearch_create, on: :create, if: :maintaining_elasticsearch?
after_commit :maintain_elasticsearch_update, on: :update after_commit :maintain_elasticsearch_update, on: :update, if: :maintaining_elasticsearch?
after_commit :maintain_elasticsearch_destroy, on: :destroy after_commit :maintain_elasticsearch_destroy, on: :destroy, if: :maintaining_elasticsearch?
end end
end end
def maintain_elasticsearch_create 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) ElasticIndexerWorker.perform_async(:index, self.class.to_s, self.id, self.es_id)
end end
def maintain_elasticsearch_update def maintain_elasticsearch_update
return unless Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
ElasticIndexerWorker.perform_async( ElasticIndexerWorker.perform_async(
:update, :update,
self.class.to_s, self.class.to_s,
...@@ -59,8 +59,6 @@ module Elastic ...@@ -59,8 +59,6 @@ module Elastic
end end
def maintain_elasticsearch_destroy def maintain_elasticsearch_destroy
return unless Gitlab::CurrentSettings.elasticsearch_indexing? && self.searchable?
ElasticIndexerWorker.perform_async( ElasticIndexerWorker.perform_async(
:delete, self.class.to_s, self.id, self.es_id, es_parent: self.es_parent :delete, self.class.to_s, self.id, self.es_id, es_parent: self.es_parent
) )
......
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