filter out closed/archived/invisible topics from suggested

This commit is contained in:
Robin Ward 2013-02-19 14:38:59 -05:00
parent ba238f92c2
commit bb1156cee1
2 changed files with 30 additions and 4 deletions

View File

@ -25,7 +25,11 @@ class TopicQuery
return TopicList.new(@user, random_suggested_results_for(topic, SiteSetting.suggested_topics, exclude_topic_ids))
end
results = unread_results(per_page: SiteSetting.suggested_topics).where('topics.id NOT IN (?)', exclude_topic_ids).all
results = unread_results(per_page: SiteSetting.suggested_topics)
.where('topics.id NOT IN (?)', exclude_topic_ids)
.where(closed: false, archived: false, visible: true)
.all
results_left = SiteSetting.suggested_topics - results.size
# If we don't have enough results, go to new posts
@ -33,7 +37,11 @@ class TopicQuery
exclude_topic_ids << results.map {|t| t.id}
exclude_topic_ids.flatten!
results << new_results(per_page: results_left).where('topics.id NOT IN (?)', exclude_topic_ids).all
results << new_results(per_page: results_left)
.where('topics.id NOT IN (?)', exclude_topic_ids)
.where(closed: false, archived: false, visible: true)
.all
results.flatten!
results_left = SiteSetting.suggested_topics - results.size
@ -43,7 +51,10 @@ class TopicQuery
exclude_topic_ids << results.map {|t| t.id}
exclude_topic_ids.flatten!
results << random_suggested_results_for(topic, results_left, exclude_topic_ids).all
results << random_suggested_results_for(topic, results_left, exclude_topic_ids)
.where(closed: false, archived: false, visible: true)
.all
results.flatten!
end
end
@ -145,6 +156,7 @@ class TopicQuery
def random_suggested_results_for(topic, count, exclude_topic_ids)
results = default_list(unordered: true, per_page: count)
.where('topics.id NOT IN (?)', exclude_topic_ids)
.where(closed: false, archived: false, visible: true)
.order('RANDOM()')
results = results.where('category_id = ?', topic.category_id) if topic.category_id.present?

View File

@ -220,8 +220,19 @@ describe TopicQuery do
it "should return the new topic" do
TopicQuery.new.list_suggested_for(topic).topics.should == [new_topic]
end
end
end
context "anonymously browswing with invisible, closed and archived" do
let!(:topic) { Fabricate(:topic) }
let!(:regular_topic) { Fabricate(:post, user: creator).topic }
let!(:closed_topic) { Fabricate(:topic, user: creator, closed: true) }
let!(:archived_topic) { Fabricate(:topic, user: creator, archived: true) }
let!(:invisible_topic) { Fabricate(:topic, user: creator, visible: false) }
it "should omit the closed/archived/invisbiel topics from suggested" do
TopicQuery.new.list_suggested_for(topic).topics.should == [regular_topic]
end
end
context 'when logged in' do
@ -237,6 +248,9 @@ describe TopicQuery do
let!(:partially_read) { Fabricate(:post, user: creator).topic }
let!(:new_topic) { Fabricate(:post, user: creator).topic }
let!(:fully_read) { Fabricate(:post, user: creator).topic }
let!(:closed_topic) { Fabricate(:topic, user: creator, closed: true) }
let!(:archived_topic) { Fabricate(:topic, user: creator, archived: true) }
let!(:invisible_topic) { Fabricate(:topic, user: creator, visible: false) }
before do
user.auto_track_topics_after_msecs = 0