1 drop view community_view;
2 create view community_view as
6 (select name from user_ u where c.creator_id = u.id) as creator_name,
7 (select name from category ct where c.category_id = ct.id) as category_name,
8 (select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
9 (select count(*) from post p where p.community_id = c.id) as number_of_posts,
10 (select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments,
11 hot_rank((select count(*) from community_follower cf where cf.community_id = c.id), c.published) as hot_rank
18 (select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
20 cross join all_community ac