Commit bf96377f authored by Mark Chao's avatar Mark Chao

Cleanup unused update_index

After 2b9ca1d1,
Indexer would automatically choose last commit to start indexing from.
parent 346eb5cb
...@@ -10,15 +10,15 @@ class ElasticBatchProjectIndexerWorker ...@@ -10,15 +10,15 @@ class ElasticBatchProjectIndexerWorker
# necessary # necessary
sidekiq_options retry: 10 sidekiq_options retry: 10
def perform(start, finish, update_index = false) def perform(start, finish)
projects = build_relation(start, finish) projects = build_relation(start, finish)
projects.find_each { |project| run_indexer(project, update_index) } projects.find_each { |project| run_indexer(project) }
end end
private private
def run_indexer(project, update_index) def run_indexer(project)
return unless project.use_elasticsearch? return unless project.use_elasticsearch?
# Ensure we remove the hold on the project, no matter what, so ElasticCommitIndexerWorker can do its thing # Ensure we remove the hold on the project, no matter what, so ElasticCommitIndexerWorker can do its thing
......
...@@ -19,7 +19,7 @@ namespace :gitlab do ...@@ -19,7 +19,7 @@ namespace :gitlab do
print "Enqueuing project repositories in batches of #{batch_size}" print "Enqueuing project repositories in batches of #{batch_size}"
project_id_batches do |start, finish| project_id_batches do |start, finish|
ElasticBatchProjectIndexerWorker.perform_async(start, finish, ENV['UPDATE_INDEX']) ElasticBatchProjectIndexerWorker.perform_async(start, finish)
print "." print "."
end end
...@@ -41,7 +41,7 @@ namespace :gitlab do ...@@ -41,7 +41,7 @@ namespace :gitlab do
Sidekiq::Logging.logger = Logger.new(STDOUT) Sidekiq::Logging.logger = Logger.new(STDOUT)
project_id_batches do |start, finish| project_id_batches do |start, finish|
ElasticBatchProjectIndexerWorker.new.perform(start, finish, ENV['UPDATE_INDEX']) ElasticBatchProjectIndexerWorker.new.perform(start, finish)
end end
end end
......
...@@ -16,7 +16,7 @@ describe ElasticBatchProjectIndexerWorker do ...@@ -16,7 +16,7 @@ describe ElasticBatchProjectIndexerWorker do
end end
it 'only indexes the enabled project' do it 'only indexes the enabled project' do
projects.each { |project| expect_index(project, false).and_call_original } projects.each { |project| expect_index(project).and_call_original }
expect(Gitlab::Elastic::Indexer).to receive(:new).with(projects.first).and_return(double(run: true)) expect(Gitlab::Elastic::Indexer).to receive(:new).with(projects.first).and_return(double(run: true))
expect(Gitlab::Elastic::Indexer).not_to receive(:new).with(projects.last) expect(Gitlab::Elastic::Indexer).not_to receive(:new).with(projects.last)
...@@ -26,14 +26,14 @@ describe ElasticBatchProjectIndexerWorker do ...@@ -26,14 +26,14 @@ describe ElasticBatchProjectIndexerWorker do
end end
it 'runs the indexer for projects in the batch range' do it 'runs the indexer for projects in the batch range' do
projects.each { |project| expect_index(project, false) } projects.each { |project| expect_index(project) }
worker.perform(projects.first.id, projects.last.id) worker.perform(projects.first.id, projects.last.id)
end end
it 'skips projects not in the batch range' do it 'skips projects not in the batch range' do
expect_index(projects.first, false).never expect_index(projects.first).never
expect_index(projects.last, false) expect_index(projects.last)
worker.perform(projects.last.id, projects.last.id) worker.perform(projects.last.id, projects.last.id)
end end
...@@ -41,7 +41,7 @@ describe ElasticBatchProjectIndexerWorker do ...@@ -41,7 +41,7 @@ describe ElasticBatchProjectIndexerWorker do
it 'clears the "locked" state from redis when the project finishes indexing' do it 'clears the "locked" state from redis when the project finishes indexing' do
Gitlab::Redis::SharedState.with { |redis| redis.sadd(:elastic_projects_indexing, projects.first.id) } Gitlab::Redis::SharedState.with { |redis| redis.sadd(:elastic_projects_indexing, projects.first.id) }
expect_index(projects.first, false).and_call_original expect_index(projects.first).and_call_original
expect_next_instance_of(Gitlab::Elastic::Indexer) do |indexer| expect_next_instance_of(Gitlab::Elastic::Indexer) do |indexer|
expect(indexer).to receive(:run) expect(indexer).to receive(:run)
end end
...@@ -50,40 +50,27 @@ describe ElasticBatchProjectIndexerWorker do ...@@ -50,40 +50,27 @@ describe ElasticBatchProjectIndexerWorker do
.to change { project_locked?(projects.first) }.from(true).to(false) .to change { project_locked?(projects.first) }.from(true).to(false)
end end
context 'update_index = false' do it 'reindexes projects that were already indexed' do
it 'indexes all projects it receives even if already indexed' do expect_index(projects.first)
projects.first.index_status.update!(last_commit: 'foo') expect_index(projects.last)
expect_index(projects.first, false).and_call_original worker.perform(projects.first.id, projects.last.id)
expect_next_instance_of(Gitlab::Elastic::Indexer) do |indexer|
expect(indexer).to receive(:run)
end
worker.perform(projects.first.id, projects.first.id)
end
end end
context 'with update_index' do it 'indexes all projects it receives even if already indexed' do
it 'reindexes projects that were already indexed' do projects.first.index_status.update!(last_commit: 'foo')
expect_index(projects.first, true)
expect_index(projects.last, true)
worker.perform(projects.first.id, projects.last.id, true) expect_index(projects.first).and_call_original
expect_next_instance_of(Gitlab::Elastic::Indexer) do |indexer|
expect(indexer).to receive(:run)
end end
it 'starts indexing at the last indexed commit' do worker.perform(projects.first.id, projects.first.id)
projects.first.index_status.update!(last_commit: 'foo')
expect_index(projects.first, true).and_call_original
expect_any_instance_of(Gitlab::Elastic::Indexer).to receive(:run)
worker.perform(projects.first.id, projects.first.id, true)
end
end end
end end
def expect_index(project, update_index) def expect_index(project)
expect(worker).to receive(:run_indexer).with(project, update_index) expect(worker).to receive(:run_indexer).with(project)
end end
def project_locked?(project) def project_locked?(project)
......
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