Commit 1e4c07a6 authored by Terri Chu's avatar Terri Chu

Change ElasticDeleteProjectWorker to delete by project_id

parent 00d3a4eb
...@@ -25,16 +25,18 @@ class ElasticDeleteProjectWorker ...@@ -25,16 +25,18 @@ class ElasticDeleteProjectWorker
bool: { bool: {
should: [ should: [
{ {
has_parent: { term: {
parent_type: 'project', _id: es_id
query: {
term: { id: project_id }
} }
},
{
term: {
project_id: project_id
} }
}, },
{ {
term: { term: {
_id: es_id target_project_id: project_id # handle merge_request which aliases project_id to target_project_id
} }
} }
] ]
......
...@@ -14,7 +14,7 @@ RSpec.describe ElasticDeleteProjectWorker, :elastic do ...@@ -14,7 +14,7 @@ RSpec.describe ElasticDeleteProjectWorker, :elastic do
stub_ee_application_setting(elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_indexing: true)
end end
it 'deletes a project with all nested objects' do it 'deletes a project with all nested objects', :aggregate_failures do
project = create :project, :repository project = create :project, :repository
issue = create :issue, project: project issue = create :issue, project: project
milestone = create :milestone, project: project milestone = create :milestone, project: project
...@@ -38,5 +38,12 @@ RSpec.describe ElasticDeleteProjectWorker, :elastic do ...@@ -38,5 +38,12 @@ RSpec.describe ElasticDeleteProjectWorker, :elastic do
expect(Milestone.elastic_search('*', **search_options).total_count).to be(0) expect(Milestone.elastic_search('*', **search_options).total_count).to be(0)
expect(Note.elastic_search('*', **search_options).total_count).to be(0) expect(Note.elastic_search('*', **search_options).total_count).to be(0)
expect(MergeRequest.elastic_search('*', **search_options).total_count).to be(0) expect(MergeRequest.elastic_search('*', **search_options).total_count).to be(0)
# verify that entire index is empty
# searches use joins on the parent record (project)
# and the previous queries will not find data left in the index
helper = Gitlab::Elastic::Helper.default
expect(helper.documents_count).to be(0)
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