1 create view comment_view as
6 (select community_id from post p where p.id = c.post_id),
7 (select u.banned from user_ u where c.creator_id = u.id) as banned,
8 (select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community,
9 (select name from user_ where c.creator_id = user_.id) as creator_name,
10 coalesce(sum(cl.score), 0) as score,
11 count (case when cl.score = 1 then 1 else null end) as upvotes,
12 count (case when cl.score = -1 then 1 else null end) as downvotes
14 left join comment_like cl on c.id = cl.comment_id
21 coalesce(cl.score, 0) as my_vote,
22 (select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved
24 cross join all_comment ac
25 left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id
37 create view reply_view as
41 c2.creator_id as sender_id,
42 c.creator_id as recipient_id
44 inner join comment c2 on c.id = c2.parent_id
45 where c2.creator_id != c.creator_id
46 -- Do union where post is null
50 c.creator_id as sender_id,
51 p.creator_id as recipient_id
52 from comment c, post p
53 where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id
56 closereply.recipient_id
57 from comment_view cv, closereply
58 where closereply.id = cv.id