mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 10:06:32 +08:00
FIX: Post#summary
returning posts from other topics.
This commit is contained in:
parent
c5cc582549
commit
6ddd214476
|
@ -344,13 +344,12 @@ class Post < ActiveRecord::Base
|
||||||
order('sort_order desc, post_number desc')
|
order('sort_order desc, post_number desc')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.summary(topic_id = nil)
|
def self.summary(topic_id)
|
||||||
# PERF: if you pass in nil it is WAY slower
|
topic_id = topic_id.to_i
|
||||||
# pg chokes getting a reasonable plan
|
|
||||||
topic_id = topic_id ? topic_id.to_i : "posts.topic_id"
|
|
||||||
|
|
||||||
# percent rank has tons of ties
|
# percent rank has tons of ties
|
||||||
where(["post_number = 1 or id in (
|
where(topic_id: topic_id)
|
||||||
|
.where(["(post_number = 1) or id in (
|
||||||
SELECT p1.id
|
SELECT p1.id
|
||||||
FROM posts p1
|
FROM posts p1
|
||||||
WHERE p1.percent_rank <= ? AND
|
WHERE p1.percent_rank <= ? AND
|
||||||
|
|
|
@ -805,12 +805,13 @@ describe Post do
|
||||||
let!(:p1) { Fabricate(:post, post_args.merge(score: 4, percent_rank: 0.33)) }
|
let!(:p1) { Fabricate(:post, post_args.merge(score: 4, percent_rank: 0.33)) }
|
||||||
let!(:p2) { Fabricate(:post, post_args.merge(score: 10, percent_rank: 0.66)) }
|
let!(:p2) { Fabricate(:post, post_args.merge(score: 10, percent_rank: 0.66)) }
|
||||||
let!(:p3) { Fabricate(:post, post_args.merge(score: 5, percent_rank: 0.99)) }
|
let!(:p3) { Fabricate(:post, post_args.merge(score: 5, percent_rank: 0.99)) }
|
||||||
|
let!(:p4) { Fabricate(:post, percent_rank: 0.99) }
|
||||||
|
|
||||||
it "returns the OP and posts above the threshold in summary mode" do
|
it "returns the OP and posts above the threshold in summary mode" do
|
||||||
SiteSetting.summary_percent_filter = 66
|
SiteSetting.summary_percent_filter = 66
|
||||||
expect(Post.summary.order(:post_number)).to eq([p1, p2])
|
expect(Post.summary(topic.id).order(:post_number)).to eq([p1, p2])
|
||||||
|
expect(Post.summary(p4.topic.id)).to eq([p4])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'sort_order' do
|
context 'sort_order' do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user