Commit 0c9302ec authored by Nick Thomas's avatar Nick Thomas Committed by Dylan Griffith

Complete elasticsearch tracking refactor

In https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24895 we
simplified the maintenance story for Elasticsearch record hooks.
However, we missed two places where `ElasticIndexWorker` was enqueued
directly instead of going through the new hooks.

When https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24298 is
merged, it will introduce significantly more conditionality into these
hooks, so it's important that every part of GitLab uses them.
parent 94afc015
......@@ -5,10 +5,9 @@ module EE
extend ActiveSupport::Concern
prepended do
# Ensure changes to project visibility settings go to elasticsearch
after_commit on: :update do
if project.use_elasticsearch?
ElasticIndexerWorker.perform_async(:update, 'Project', project_id, project.es_id)
end
project.maintain_elasticsearch_update if project.maintaining_elasticsearch?
end
end
end
......
......@@ -23,21 +23,11 @@ module EE
end
override :post_update_hooks
# rubocop: disable CodeReuse/ActiveRecord
def post_update_hooks(updated_project_ids)
::Project.where(id: updated_project_ids).find_each do |project|
# TODO: Refactor out this duplication per https://gitlab.com/gitlab-org/gitlab/issues/38232
if ::Gitlab::CurrentSettings.elasticsearch_indexing? && project.searchable?
ElasticIndexerWorker.perform_async(
:update,
project.class.to_s,
project.id,
project.es_id
)
end
::Project.id_in(updated_project_ids).find_each do |project|
project.maintain_elasticsearch_update if project.maintaining_elasticsearch?
end
end
# rubocop: enable CodeReuse/ActiveRecord
def raise_ee_transfer_error(message)
raise ::Groups::TransferService::TransferError, EE_ERROR_MESSAGES[message]
......
......@@ -79,7 +79,7 @@ describe Groups::TransferService, '#execute' do
stub_ee_application_setting(elasticsearch_indexing: true)
end
it 'reindexes projects' do
it 'reindexes projects', :elastic do
project1 = create(:project, :repository, :public, namespace: group)
project2 = create(:project, :repository, :public, namespace: group)
project3 = create(:project, :repository, :private, namespace: group)
......
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