Commit b5ed9e38 authored by Katrin Leinweber's avatar Katrin Leinweber Committed by Dmitry Gruzd

Ignore unindexed projects that have no repository

Changelog: changed
EE: true
parent d853a87a
......@@ -160,7 +160,15 @@ namespace :gitlab do
desc "GitLab | Elasticsearch | Display which projects are not indexed"
task projects_not_indexed: :environment do
not_indexed = Project.where.not(id: IndexStatus.select(:project_id).distinct)
not_indexed = []
Project.where.not(id: IndexStatus.select(:project_id).distinct).each_batch do |batch|
batch.each do |project|
next if !project.repository_exists? || project.empty_repo?
not_indexed << project
end
end
if not_indexed.count == 0
puts 'All projects are currently indexed'.color(:green)
......@@ -271,9 +279,7 @@ namespace :gitlab do
projects[1..500]
end
arr.each do |p|
puts "Project '#{p.full_path}' (ID: #{p.id}) isn't indexed.".color(:red)
end
arr.each { |p| puts "Project '#{p.full_path}' (ID: #{p.id}) isn't indexed.".color(:red) }
puts "#{arr.count} out of #{projects.count} non-indexed projects shown."
end
......
......@@ -348,4 +348,37 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic, :silence_stdout
end
end
end
describe 'projects_not_indexed' do
subject { run_rake_task('gitlab:elastic:projects_not_indexed') }
let_it_be(:project) { create(:project, :repository) }
context 'no projects are indexed' do
it 'displays non-indexed projects' do
expected = <<~END
Project '#{project.full_path}' (ID: #{project.id}) isn't indexed.
1 out of 1 non-indexed projects shown.
END
expect { subject }.to output(expected).to_stdout
end
end
context 'all projects are indexed' do
before do
IndexStatus.create!(project: project, indexed_at: Time.current, last_commit: 'foo')
end
it 'displays that all projects are indexed' do
expect { subject }.to output(/All projects are currently indexed/).to_stdout
end
it 'does not include projects without repositories' do
create(:project)
expect { subject }.to output(/All projects are currently indexed/).to_stdout
end
end
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