From ff5fc3cb082de4f9f577fca34a8e96f1b1f7cd16 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 20 Jun 2018 16:58:52 +0800 Subject: [PATCH] Use a fixed limit for mega topic posts count. --- lib/topic_view.rb | 6 ++++-- spec/components/topic_view_spec.rb | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 14fb158c2e2..88cd9d15239 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -378,7 +378,7 @@ class TopicView columns = [:id, :post_number] - if is_mega_topic? + if !is_mega_topic? columns << 'EXTRACT(DAYS FROM CURRENT_TIMESTAMP - created_at)::INT AS days_ago' end @@ -563,7 +563,9 @@ class TopicView filtered_post_ids.index(closest_post.first) || filtered_post_ids[0] end + MEGA_TOPIC_POSTS_COUNT = 10000 + def is_mega_topic? - !@topic.private_message? && @topic.posts_count >= SiteSetting.auto_close_topics_post_count + @topic.posts_count >= MEGA_TOPIC_POSTS_COUNT end end diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index a905b665bf0..17e1eedcafb 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -565,13 +565,20 @@ describe TopicView do describe 'for mega topics' do it 'should return the right columns' do - SiteSetting.auto_close_topics_post_count = 2 + begin + original_const = TopicView::MEGA_TOPIC_POSTS_COUNT + TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT") + TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", 2) - expect(topic_view.filtered_post_stream).to eq([ - [post.id, post.post_number], - [post2.id, post2.post_number], - [post3.id, post3.post_number] - ]) + expect(topic_view.filtered_post_stream).to eq([ + [post.id, post.post_number], + [post2.id, post2.post_number], + [post3.id, post3.post_number] + ]) + ensure + TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT") + TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", original_const) + end end end end