PERF: fix slow query

This commit is contained in:
Sam 2014-07-01 22:00:57 +10:00
parent bc44bfcdf2
commit 03f63d970b
1 changed files with 4 additions and 3 deletions

View File

@ -43,9 +43,10 @@ class Search
def self.rebuild_problem_posts(limit = 10000)
posts = Post.joins(:topic)
.where('posts.id NOT IN (
SELECT post_id from post_search_data
WHERE locale = ?
.where('posts.id IN (
SELECT p2.id FROM posts p2
LEFT JOIN post_search_data pd ON locale = ? AND p2.id = pd.post_id
WHERE pd.post_id IS NULL
)', SiteSetting.default_locale).limit(10000)
posts.each do |post|