Created
July 15, 2013 20:47
-
-
Save bplexico/6003316 to your computer and use it in GitHub Desktop.
add get_topic_totals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
totals = get_topic_totals | |
def get_topic_totals | |
Topic.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