FIX: Don't reindex posts belonging to a deleted topic for search.
Posts belonging to a deleted topic can't be index for search so we need to avoid loading those post ids.
This commit is contained in:
parent
3fc5dbb045
commit
aa2311a7b0
|
@ -69,16 +69,28 @@ module Jobs
|
|||
end
|
||||
|
||||
def load_problem_post_ids(limit)
|
||||
Post
|
||||
.where('posts.id IN (
|
||||
SELECT p2.id FROM posts p2
|
||||
LEFT JOIN post_search_data pd ON pd.locale = ? AND pd.version = ? AND p2.id = pd.post_id
|
||||
WHERE pd.post_id IS NULL
|
||||
)', SiteSetting.default_locale, Search::INDEX_VERSION)
|
||||
.where("posts.raw != ''")
|
||||
.limit(limit)
|
||||
.order('posts.id DESC')
|
||||
.pluck(:id)
|
||||
params = {
|
||||
locale: SiteSetting.default_locale,
|
||||
version: Search::INDEX_VERSION,
|
||||
limit: limit
|
||||
}
|
||||
|
||||
DB.query_single(<<~SQL, params)
|
||||
SELECT
|
||||
posts.id
|
||||
FROM posts
|
||||
LEFT JOIN post_search_data pd
|
||||
ON pd.locale = :locale
|
||||
AND pd.version = :version
|
||||
AND pd.post_id = posts.id
|
||||
LEFT JOIN topics ON topics.id = posts.topic_id
|
||||
WHERE pd.post_id IS NULL
|
||||
AND topics.id IS NOT NULL
|
||||
AND topics.deleted_at IS NULL
|
||||
AND posts.raw != ''
|
||||
ORDER BY posts.id DESC
|
||||
LIMIT :limit
|
||||
SQL
|
||||
end
|
||||
|
||||
def load_problem_category_ids(limit)
|
||||
|
|
|
@ -49,6 +49,18 @@ describe Jobs::ReindexSearch do
|
|||
FakeIndexer.reset
|
||||
end
|
||||
|
||||
it 'should not reinex posts that belong to a deleted topic' do
|
||||
post = Fabricate(:post)
|
||||
post2 = Fabricate(:post)
|
||||
post.post_search_data.destroy!
|
||||
post2.post_search_data.destroy!
|
||||
post2.topic.trash!
|
||||
|
||||
subject.rebuild_problem_posts(indexer: FakeIndexer)
|
||||
|
||||
expect(FakeIndexer.posts).to contain_exactly(post)
|
||||
end
|
||||
|
||||
it 'should not reindex posts with empty raw' do
|
||||
post = Fabricate(:post)
|
||||
post.post_search_data.destroy!
|
||||
|
|
Loading…
Reference in New Issue