PERF: eliminate query that grabs every post number on topic page.

This commit is contained in:
Sam Saffron 2015-04-23 00:10:09 +10:00
parent 40b22bf367
commit 27aa0bc056
1 changed files with 3 additions and 3 deletions

View File

@ -416,10 +416,10 @@ class TopicView
end end
def closest_post_to(post_number) def closest_post_to(post_number)
closest_posts = filter_post_ids_by("@(post_number - #{post_number})") closest_post = @filtered_posts.order("@(post_number - #{post_number})").limit(1).pluck(:id)
return nil if closest_posts.empty? return nil if closest_post.empty?
filtered_post_ids.index(closest_posts.first) || filtered_post_ids[0] filtered_post_ids.index(closest_post.first) || filtered_post_ids[0]
end end
end end