Commit fe0e9e2b authored by Nick Thomas's avatar Nick Thomas

Merge branch '12362-indexing-projects-on-import' into 'master'

Respect limited indexing when importing projects

See merge request gitlab-org/gitlab-ee!14413
parents f1513e46 4fb08844
......@@ -62,7 +62,7 @@ module EE
end
after_transition started: :finished do |state, _|
if ::Gitlab::CurrentSettings.current_application_settings.elasticsearch_indexing?
if state.project.use_elasticsearch?
state.run_after_commit do
last_indexed_commit = state.project.index_status&.last_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
context 'namespaces' do
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
create :elasticsearch_indexed_namespace, namespace: namespaces.last
expect(setting.elasticsearch_indexes_namespace?(namespaces.last)).to be_truthy
expect(setting.elasticsearch_indexes_namespace?(namespaces.first)).to be_falsey
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
context 'projects' do
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
create :elasticsearch_indexed_project, project: projects.last
expect(setting.elasticsearch_indexes_project?(projects.last)).to be_truthy
expect(setting.elasticsearch_indexes_project?(projects.first)).to be_falsey
expect(setting.elasticsearch_indexes_project?(projects.last)).to be(true)
expect(setting.elasticsearch_indexes_project?(projects.first)).to be(false)
end
end
it 'returns projects that are allowed to be indexed' do
project1 = create(:project)
projects = create_list(:project, 3)
it 'returns projects that are allowed to be indexed' do
project_indexed_through_namespace = create(:project)
create :elasticsearch_indexed_namespace, namespace: project_indexed_through_namespace.namespace
create :elasticsearch_indexed_namespace, namespace: project1.namespace
projects.each { |project| create :elasticsearch_indexed_project, project: project }
expect(setting.elasticsearch_limited_projects).to match_array(projects << project1)
expect(setting.elasticsearch_limited_projects).to match_array(
[projects.last, project_indexed_through_namespace])
end
end
end
end
......
......@@ -28,42 +28,39 @@ describe ProjectImportState, type: :model do
end
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 'elasticsearch indexing disabled' do
context 'elasticsearch indexing disabled for this project' do
before do
stub_ee_application_setting(elasticsearch_indexing: false)
expect(project).to receive(:use_elasticsearch?).and_return(false)
end
it 'does not index the repository' do
import_state = create(:import_state, :started, import_type: :github)
expect(ElasticCommitIndexerWorker).not_to receive(:perform_async)
import_state.finish
end
end
context 'elasticsearch indexing enabled' do
let(:import_state) { create(:import_state, :started, import_type: :github) }
context 'elasticsearch indexing enabled for this project' do
before do
stub_ee_application_setting(elasticsearch_indexing: true)
expect(project).to receive(:use_elasticsearch?).and_return(true)
end
context 'no index status' 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
end
end
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
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)
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