Commit fbe44b72 authored by Sean McGivern's avatar Sean McGivern

Merge branch '37327-fix-duplicate-container-ids' into 'master'

Fix check for existing ES limited indexing IDs

See merge request gitlab-org/gitlab!20866
parents 438b8ef4 677d5a4d
......@@ -25,10 +25,10 @@ module EE
def update_elasticsearch_containers(klass, new_container_ids)
return unless application_setting.elasticsearch_limit_indexing?
new_container_ids = new_container_ids&.split(",") unless new_container_ids.is_a?(Array)
return if new_container_ids.nil?
new_container_ids = new_container_ids.split(',').map(&:to_i) unless new_container_ids.is_a?(Array)
# Destroy any containers that have been removed. This runs callbacks, etc
klass.remove_all(except: new_container_ids)
......
---
title: Fix check for existing ES limited indexing IDs
merge_request: 20866
author:
type: fixed
......@@ -91,6 +91,17 @@ describe ApplicationSettings::UpdateService do
expect(ElasticsearchIndexedNamespace.where(namespace_id: namespaces.last.id)).not_to exist
end
it 'disregards already existing ElasticsearchIndexedNamespace in elasticsearch_namespace_ids' do
create :elasticsearch_indexed_namespace, namespace: namespaces.first
opts = { elasticsearch_namespace_ids: namespaces.first(2).map(&:id).join(',') }
expect do
described_class.new(setting, user, opts).execute
end.to change { ElasticsearchIndexedNamespace.count }.from(1).to(2)
expect(ElasticsearchIndexedNamespace.pluck(:namespace_id)).to eq([namespaces.first.id, namespaces.second.id])
end
end
context 'projects' do
......@@ -114,6 +125,17 @@ describe ApplicationSettings::UpdateService do
expect(ElasticsearchIndexedProject.where(project_id: projects.last.id)).not_to exist
end
it 'disregards already existing ElasticsearchIndexedProject in elasticsearch_project_ids' do
create :elasticsearch_indexed_project, project: projects.first
opts = { elasticsearch_project_ids: projects.first(2).map(&:id).join(',') }
expect do
described_class.new(setting, user, opts).execute
end.to change { ElasticsearchIndexedProject.count }.from(1).to(2)
expect(ElasticsearchIndexedProject.pluck(:project_id)).to eq([projects.first.id, projects.second.id])
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