Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Forced summary mode for megalodon topics.

Guo Xiang Tanf7d22bad903b
diff --git a/app/models/post.rb b/app/models/post.rb
index 5e736977101..14d57b824ef 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -355,7 +355,7 @@ class Post < ActiveRecord::Base
SELECT posts.id
FROM posts
WHERE posts.topic_id = #{topic_id.to_i}
- AND post_number = 1
+ AND posts.post_number = 1
) UNION
(
SELECT p1.id
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index 2b3dc236c4f..d180db56820 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -482,9 +482,9 @@ class TopicView
@filtered_posts = unfiltered_posts
# Filters
- if @filter == 'summary'
+ if @filter == 'summary' || force_summary_mode?
@filtered_posts = @filtered_posts.summary(@topic.id)
- @contains_gaps = true
+ @contains_gaps = true unless force_summary_mode?
end
if @best.present?
@@ -572,4 +572,9 @@ class TopicView
def is_mega_topic?
@topic.posts_count >= MEGA_TOPIC_POSTS_COUNT
end
+
+ def force_summary_mode?
+ @force_summary_mode ||=
+ (@topic.closed? && @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2))
+ end
end
diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb
index 17e1eedcafb..241649187b2 100644
--- a/spec/components/topic_view_spec.rb
+++ b/spec/components/topic_view_spec.rb
@@ -364,6 +364,26 @@ describe TopicView do
end
end
+ describe 'when a megalodon topic is closed' do
+ it 'should be forced into summary mode without gaps' do
+ begin
+ original_const = TopicView::MEGA_TOPIC_POSTS_COUNT
+ TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT")
+ TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", 1)
+ SiteSetting.summary_max_results = 2
+ topic.update!(closed: true)
+
+ topic_view = TopicView.new(topic.id, evil_trout)
+
+ expect(topic_view.contains_gaps?).to eq(false)
+ expect(topic_view.posts).to eq([p5])
+ ensure
+ TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT")
+ TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", original_const)
+ end
+ end
+ end
+
it "#restricts to correct topic" do
t2 = Fabricate(:topic)