Skip to content

Instantly share code, notes, and snippets.

@bplexico
Created July 15, 2013 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bplexico/6003510 to your computer and use it in GitHub Desktop.
Save bplexico/6003510 to your computer and use it in GitHub Desktop.
new methods in Topic
def self.uncategorized_topics
listable_topics
.visible
.where(category_id: nil)
.topic_list_order
.limit(SiteSetting.category_featured_topics)
end
def self.totals
exec_sql("SELECT SUM(CASE WHEN created_at >= (CURRENT_TIMESTAMP - INTERVAL '1 WEEK') THEN 1 ELSE 0 END) as topics_week,
SUM(CASE WHEN created_at >= (CURRENT_TIMESTAMP - INTERVAL '1 MONTH') THEN 1 ELSE 0 END) as topics_month,
SUM(CASE WHEN created_at >= (CURRENT_TIMESTAMP - INTERVAL '1 YEAR') THEN 1 ELSE 0 END) as topics_year,
COUNT(*) AS topic_count
FROM topics
WHERE topics.visible
AND topics.deleted_at IS NULL
AND topics.category_id IS NULL
AND topics.archetype <> '#{Archetype.private_message}'").first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment