Commit 76dadf3d authored by Mark Chao's avatar Mark Chao

Extract project's indexing association as method

parent d82412f4
...@@ -12,6 +12,14 @@ module Elastic ...@@ -12,6 +12,14 @@ module Elastic
repository_access_level repository_access_level
).freeze ).freeze
INDEXED_ASSOCIATIONS = [
:issues,
:merge_requests,
:snippets,
:notes,
:milestones
].freeze
included do included do
include ApplicationSearch include ApplicationSearch
...@@ -97,6 +105,26 @@ module Elastic ...@@ -97,6 +105,26 @@ module Elastic
self.__elasticsearch__.search(query_hash) self.__elasticsearch__.search(query_hash)
end end
def self.indexed_association_classes
INDEXED_ASSOCIATIONS.map do |association_name|
reflect_on_association(association_name).klass
end
end
def each_indexed_association
INDEXED_ASSOCIATIONS.each do |association_name|
association = self.association(association_name)
scope = association.scope
klass = association.klass
if klass == Note
scope = scope.searchable
end
yield klass, scope
end
end
end end
end end
end end
...@@ -62,13 +62,7 @@ class ElasticIndexerWorker ...@@ -62,13 +62,7 @@ class ElasticIndexerWorker
end end
def initial_index_project(project) def initial_index_project(project)
{ project.each_indexed_association do |klass, objects|
Issue => project.issues,
MergeRequest => project.merge_requests,
Snippet => project.snippets,
Note => project.notes.searchable,
Milestone => project.milestones
}.each do |klass, objects|
objects.find_each { |object| import(:index, object, klass) } objects.find_each { |object| import(:index, object, klass) }
end end
......
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