FIX: summary mode was broken and missing a bunch of posts

This commit is contained in:
Sam 2015-01-30 17:19:42 +11:00
parent 784697bf12
commit 52bc03b5e6
2 changed files with 18 additions and 3 deletions

View file

@ -251,8 +251,23 @@ class Post < ActiveRecord::Base
order('sort_order desc, post_number desc')
end
def self.summary
where(["(post_number = 1) or (percent_rank <= ?)", SiteSetting.summary_percent_filter.to_f / 100.0]).limit(SiteSetting.summary_max_results)
def self.summary(topic_id=nil)
# PERF: if you pass in nil it is WAY slower
# pg chokes getting a reasonable plan
topic_id = topic_id ? topic_id.to_i : "posts.topic_id"
# percent rank has tons of ties
where(["post_number = 1 or id in (
SELECT p1.id
FROM posts p1
WHERE p1.percent_rank <= ? AND
p1.topic_id = #{topic_id}
ORDER BY p1.percent_rank
LIMIT ?
)",
SiteSetting.summary_percent_filter.to_f / 100.0,
SiteSetting.summary_max_results
])
end
def update_flagged_posts_count

View file

@ -342,7 +342,7 @@ class TopicView
# Filters
if @filter == 'summary'
@filtered_posts = @filtered_posts.summary
@filtered_posts = @filtered_posts.summary(@topic.id)
@contains_gaps = true
end