Commit 4fb08844 authored by Markus Koller's avatar Markus Koller

Respect limited indexing when importing projects

Every time a project is imported, an `ElasticCommitIndexerWorker` was
unconditionally enqueued. We do check `project.use_elasticsearch?`
inside `ElasticCommitIndexerWorker#perform` so the job ends up being a
no-op, but since it doesn't do anything we also don't need to queue it.
parent 09796eca
...@@ -62,7 +62,7 @@ module EE ...@@ -62,7 +62,7 @@ module EE
end end
after_transition started: :finished do |state, _| after_transition started: :finished do |state, _|
if ::Gitlab::CurrentSettings.current_application_settings.elasticsearch_indexing? if state.project.use_elasticsearch?
state.run_after_commit do state.run_after_commit do
last_indexed_commit = state.project.index_status&.last_commit last_indexed_commit = state.project.index_status&.last_commit
ElasticCommitIndexerWorker.perform_async(state.project_id, last_indexed_commit) ElasticCommitIndexerWorker.perform_async(state.project_id, last_indexed_commit)
......
---
title: Respect limited indexing when importing projects
merge_request: 14413
author:
type: fixed
...@@ -211,34 +211,42 @@ describe ApplicationSetting do ...@@ -211,34 +211,42 @@ describe ApplicationSetting do
context 'namespaces' do context 'namespaces' do
let(:namespaces) { create_list(:namespace, 2) } let(:namespaces) { create_list(:namespace, 2) }
let!(:indexed_namespace) { create :elasticsearch_indexed_namespace, namespace: namespaces.last }
it 'tells you if a namespace is allowed to be indexed' do it 'tells you if a namespace is allowed to be indexed' do
create :elasticsearch_indexed_namespace, namespace: namespaces.last
expect(setting.elasticsearch_indexes_namespace?(namespaces.last)).to be_truthy expect(setting.elasticsearch_indexes_namespace?(namespaces.last)).to be_truthy
expect(setting.elasticsearch_indexes_namespace?(namespaces.first)).to be_falsey expect(setting.elasticsearch_indexes_namespace?(namespaces.first)).to be_falsey
end end
it 'returns namespaces that are allowed to be indexed' do
child_namespace = create(:namespace, parent: namespaces.first)
create :elasticsearch_indexed_namespace, namespace: child_namespace
child_namespace_indexed_through_parent = create(:namespace, parent: namespaces.last)
expect(setting.elasticsearch_limited_namespaces).to match_array(
[namespaces.last, child_namespace, child_namespace_indexed_through_parent])
expect(setting.elasticsearch_limited_namespaces(true)).to match_array(
[namespaces.last, child_namespace])
end
end end
context 'projects' do context 'projects' do
let(:projects) { create_list(:project, 2) } let(:projects) { create_list(:project, 2) }
let!(:indexed_project) { create :elasticsearch_indexed_project, project: projects.last }
it 'tells you if a project is allowed to be indexed' do it 'tells you if a project is allowed to be indexed' do
create :elasticsearch_indexed_project, project: projects.last expect(setting.elasticsearch_indexes_project?(projects.last)).to be(true)
expect(setting.elasticsearch_indexes_project?(projects.first)).to be(false)
expect(setting.elasticsearch_indexes_project?(projects.last)).to be_truthy
expect(setting.elasticsearch_indexes_project?(projects.first)).to be_falsey
end end
end
it 'returns projects that are allowed to be indexed' do it 'returns projects that are allowed to be indexed' do
project1 = create(:project) project_indexed_through_namespace = create(:project)
projects = create_list(:project, 3) create :elasticsearch_indexed_namespace, namespace: project_indexed_through_namespace.namespace
create :elasticsearch_indexed_namespace, namespace: project1.namespace expect(setting.elasticsearch_limited_projects).to match_array(
projects.each { |project| create :elasticsearch_indexed_project, project: project } [projects.last, project_indexed_through_namespace])
end
expect(setting.elasticsearch_limited_projects).to match_array(projects << project1)
end end
end end
end end
......
...@@ -28,42 +28,39 @@ describe ProjectImportState, type: :model do ...@@ -28,42 +28,39 @@ describe ProjectImportState, type: :model do
end end
describe 'transitions' do describe 'transitions' do
let(:import_state) { create(:import_state, :started, import_type: :github) }
let(:project) { import_state.project }
context 'state transition: [:started] => [:finished]' do context 'state transition: [:started] => [:finished]' do
context 'elasticsearch indexing disabled' do context 'elasticsearch indexing disabled for this project' do
before do before do
stub_ee_application_setting(elasticsearch_indexing: false) expect(project).to receive(:use_elasticsearch?).and_return(false)
end end
it 'does not index the repository' do it 'does not index the repository' do
import_state = create(:import_state, :started, import_type: :github)
expect(ElasticCommitIndexerWorker).not_to receive(:perform_async) expect(ElasticCommitIndexerWorker).not_to receive(:perform_async)
import_state.finish import_state.finish
end end
end end
context 'elasticsearch indexing enabled' do context 'elasticsearch indexing enabled for this project' do
let(:import_state) { create(:import_state, :started, import_type: :github) }
before do before do
stub_ee_application_setting(elasticsearch_indexing: true) expect(project).to receive(:use_elasticsearch?).and_return(true)
end end
context 'no index status' do context 'no index status' do
it 'schedules a full index of the repository' do it 'schedules a full index of the repository' do
expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(import_state.project_id, Gitlab::Git::BLANK_SHA) expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(import_state.project_id, nil)
import_state.finish import_state.finish
end end
end end
context 'with index status' do context 'with index status' do
let!(:index_status) { import_state.project.index_status } let(:index_status) { IndexStatus.create!(project: project, indexed_at: Time.now, last_commit: 'foo') }
it 'schedules a progressive index of the repository' do it 'schedules a progressive index of the repository' do
index_status.update!(indexed_at: Time.now, last_commit: 'foo')
expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(import_state.project_id, index_status.last_commit) expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(import_state.project_id, index_status.last_commit)
import_state.finish import_state.finish
......
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