1 DROP VIEW community_view;
12 DROP COLUMN show_nsfw;
15 CREATE VIEW community_view AS
16 with all_community AS (
25 c.creator_id = u.id) AS creator_name,
32 c.category_id = ct.id) AS category_name,
39 cf.community_id = c.id) AS number_of_subscribers,
46 p.community_id = c.id) AS number_of_posts,
55 AND p.id = co.post_id) AS number_of_comments,
59 FROM community_follower cf
61 cf.community_id = c.id), c.published) AS hot_rank
75 AND ac.id = cf.community_id) AS subscribed
78 CROSS JOIN all_community ac
88 CREATE VIEW post_view AS
98 p.creator_id = user_.id) AS creator_name,
105 p.community_id = community.id) AS community_name,
112 p.community_id = c.id) AS community_removed,
119 p.community_id = c.id) AS community_deleted,
126 comment.post_id = p.id) AS number_of_comments,
127 coalesce(sum(pl.score), 0) AS score,
129 CASE WHEN pl.score = 1 THEN
135 CASE WHEN pl.score = - 1 THEN
140 hot_rank (coalesce(sum(pl.score), 0), p.published) AS hot_rank
143 LEFT JOIN post_like pl ON p.id = pl.post_id
150 coalesce(pl.score, 0) AS my_vote,
155 community_follower cf
158 AND cf.community_id = ap.community_id) AS subscribed,
166 AND pr.post_id = ap.id) AS read,
174 AND ps.post_id = ap.id) AS saved
177 CROSS JOIN all_post ap
178 LEFT JOIN post_like pl ON u.id = pl.user_id
179 AND ap.id = pl.post_id