diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-13 12:57:36 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-13 12:57:36 +0100 |
commit | efce515bf8d5e44b23cb047165912ce817500533 (patch) | |
tree | b948237a274f9e6c3728e01eb74407fec9772c3c /schema.sql | |
parent | 4f9ac385def826e898ff43063af29bca6a22f5ba (diff) |
Reduce the number of roundtrips needed for archive page creation.
Diffstat (limited to 'schema.sql')
-rw-r--r-- | schema.sql | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -269,4 +269,26 @@ CREATE AGGREGATE most_recent_revision (article_revisions) ( STYPE = article_revisions ); + +CREATE VIEW article_comment_counts AS + SELECT a.id AS article, + count(c.*) AS comment_count + FROM articles a + LEFT JOIN comments c + ON c.article = a.id + AND EXISTS (SELECT * + FROM comment_revisions + WHERE comment = c.id + AND status IN ('approved', 'trusted')) + GROUP BY a.id; + + +CREATE VIEW article_publishing_dates AS + SELECT article AS article, + min(date) AS publishing_date + FROM article_revisions + WHERE status IN ('published', 'syndicated') + GROUP BY article; + + COMMIT; |