FEATURE: do not show category definition topic on top pages

This commit is contained in:
Régis Hanol 2014-03-07 12:02:52 +01:00
parent f52ab7fc77
commit 084f51b013

View File

@ -27,21 +27,26 @@ class TopTopic < ActiveRecord::Base
end
def self.remove_invisible_topics
exec_sql("WITH invisible_topics AS (
exec_sql("WITH category_definition_topic_ids AS (
SELECT COALESCE(topic_id, 0) AS id FROM categories
), invisible_topic_ids AS (
SELECT id
FROM topics
WHERE deleted_at IS NOT NULL
OR NOT visible
OR archetype = :private_message
OR archived
OR id IN (SELECT id FROM category_definition_topic_ids)
)
DELETE FROM top_topics
WHERE topic_id IN (SELECT id FROM invisible_topics)",
WHERE topic_id IN (SELECT id FROM invisible_topic_ids)",
private_message: Archetype::private_message)
end
def self.add_new_visible_topics
exec_sql("WITH visible_topics AS (
exec_sql("WITH category_definition_topic_ids AS (
SELECT COALESCE(topic_id, 0) AS id FROM categories
), visible_topics AS (
SELECT t.id
FROM topics t
LEFT JOIN top_topics tt ON t.id = tt.topic_id
@ -49,12 +54,12 @@ class TopTopic < ActiveRecord::Base
AND t.visible
AND t.archetype <> :private_message
AND NOT t.archived
AND t.id NOT IN (SELECT id FROM category_definition_topic_ids)
AND tt.topic_id IS NULL
)
INSERT INTO top_topics (topic_id)
SELECT id
FROM visible_topics",
private_message: Archetype::private_message)
SELECT id FROM visible_topics",
private_message: Archetype::private_message)
end
def self.update_posts_count_for(period)
@ -85,6 +90,7 @@ class TopTopic < ActiveRecord::Base
WHERE created_at >= :from
AND deleted_at IS NULL
AND NOT hidden
AND post_type = #{Post.types[:regular]}
GROUP BY topic_id"
TopTopic.update_top_topics(period, "likes", sql)
@ -113,7 +119,8 @@ class TopTopic < ActiveRecord::Base
SET #{period}_#{sort}_count = c.count
FROM top_topics tt
INNER JOIN (#{inner_join}) c ON tt.topic_id = c.topic_id
WHERE tt.topic_id = top_topics.topic_id", from: start_of(period))
WHERE tt.topic_id = top_topics.topic_id",
from: start_of(period))
end
end