Skip to content

Commit

Permalink
Do not delete descendants when a parent is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzasa committed Dec 17, 2021
1 parent 6a741fa commit 5fe694f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/chewy/index/import/bulk_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def reindex_descendants(root)
end

def delete_entry(object)
delete_single_entry(object) + delete_descendants(object)
delete_single_entry(object) # + delete_descendants(object)
end

def delete_single_entry(object, root: object)
Expand Down
14 changes: 5 additions & 9 deletions spec/chewy/index/import/bulk_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,13 @@ def root(comment)
end
end

let(:to_index) { [comments[0]].map{ |c| SimpleComment.new(c.attributes) } }
let(:delete) { [existing_comments[0]].map { |c| c } }
let(:to_index) { [comments[0]].map{ |c| SimpleComment.new(c.attributes) } } # id: 3
let(:delete) { [existing_comments[0]].map { |c| c } } # id: 1

specify do
expect(subject.bulk_body).to eq([
{index: {_id: 3, routing: '1', data: {'content' => 'There!', 'content_with_crutches' => '[crutches] There!', 'derived' => '[derived] There!', 'comment_type' => {'name' => 'answer', 'parent' => 1}}}},
{delete: {_id: 1, routing: '1'}},
{delete: {_id: 2, parent: 1, routing: '1'}}
{delete: {_id: 1, routing: '1'}}
])
end
end
Expand Down Expand Up @@ -382,12 +381,9 @@ def root(comment)
comments.each { |c| raw_index_comment(c) }
end

it 'removes all descendants' do
it 'does not remove all descendants' do
expect(subject.bulk_body).to eq([
{delete: {_id: 1, routing: '1'}},
{delete: {_id: 2, routing: '1', parent: 1}},
{delete: {_id: 3, routing: '1', parent: 2}},
{delete: {_id: 4, routing: '1', parent: 3}}
{delete: {_id: 1, routing: '1'}}
])
end
end
Expand Down

0 comments on commit 5fe694f

Please sign in to comment.