PERF: Delete search data of posts from trashed topics periodically. (#7302)

This keeps both the index and table smaller.
This commit is contained in:
Guo Xiang Tan
2019-04-03 10:10:41 +08:00
committed by GitHub
parent feb731bffd
commit d151425353
2 changed files with 34 additions and 4 deletions

View File

@@ -79,15 +79,33 @@ describe Jobs::ReindexSearch do
end
describe '#execute' do
it "should clean up post_search_data of posts with empty raw" do
it(
"should clean up post_search_data of posts with empty raw or posts from " \
"trashed topics"
) do
post = Fabricate(:post)
post2 = Fabricate(:post, post_type: Post.types[:small_action])
post2.raw = ""
post2.save!(validate: false)
post3 = Fabricate(:post)
post3.topic.trash!
post4 = nil
expect { subject.execute({}) }.to change { PostSearchData.count }.by(-1)
expect(Post.all).to contain_exactly(post, post2)
expect(PostSearchData.all).to contain_exactly(post.post_search_data)
freeze_time(1.week.ago) do
post4 = Fabricate(:post)
post4.topic.trash!
end
expect { subject.execute({}) }.to change { PostSearchData.count }.by(-2)
expect(Post.all.pluck(:id)).to contain_exactly(
post.id, post2.id, post3.id, post4.id
)
expect(PostSearchData.all.pluck(:post_id)).to contain_exactly(
post.post_search_data.post_id, post3.post_search_data.post_id
)
end
end
end