Commit 03b63f55 authored by Valery Sizov's avatar Valery Sizov

ES: fixes after review

parent 9ef5b8ae
......@@ -6,41 +6,43 @@ class ElasticIndexerWorker
Client = Elasticsearch::Client.new(host: Gitlab.config.elasticsearch.host,
port: Gitlab.config.elasticsearch.port)
def perform(operation, klass, record_id, options = {})
cklass = klass.constantize
def perform(operation, class_name, record_id, options = {})
klass = class_name.constantize
case operation.to_s
when /index|update/
record = cklass.find(record_id)
record = klass.find(record_id)
record.__elasticsearch__.client = Client
record.__elasticsearch__.__send__ "#{operation}_document"
when /delete/
Client.delete index: cklass.index_name, type: cklass.document_type, id: record_id
Client.delete index: klass.index_name, type: klass.document_type, id: record_id
if cklass == Project
# Remove repository index
Client.delete_by_query({
index: Repository.__elasticsearch__.index_name,
body: {
query: {
or: [
{ term: { "commit.rid" => record_id } },
{ term: { "blob.rid" => record_id } }
]
}
}
})
# Remove wiki index
Client.delete_by_query({
index: ProjectWiki.__elasticsearch__.index_name,
body: {
query: {
term: { "blob.rid" => "wiki_#{record_id}" }
}
}
})
end
clear_project_indexes(record_id) if klass == Project
end
end
def clear_project_indexes(record_id)
# Remove repository index
Client.delete_by_query({
index: Repository.__elasticsearch__.index_name,
body: {
query: {
or: [
{ term: { "commit.rid" => record_id } },
{ term: { "blob.rid" => record_id } }
]
}
}
})
# Remove wiki index
Client.delete_by_query({
index: ProjectWiki.__elasticsearch__.index_name,
body: {
query: {
term: { "blob.rid" => "wiki_#{record_id}" }
}
}
})
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