mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 19:31:33 +00:00
5c6258390c
* Adding a way to GetComments for a community given its name only. * Adding getcomments to api docs. * A first pass at locally working isomorphic integration. * Testing out cargo-husky. * Testing a fail hook. * Revert "Testing a fail hook." This reverts commit0941cf1736
. * Moving server to top level, now that UI is gone. * Running cargo fmt using old way. * Adding nginx, fixing up docker-compose files, fixing docs. * Trying to re-add API tests. * Fixing prod dockerfile. * Redoing nightly fmt * Trying to fix private message api test. * Adding CommunityJoin, PostJoin instead of joins from GetComments, etc. - Fixes #1122 * Fixing fmt. * Fixing up docs. * Removing translations. * Adding apps / clients to readme. * Fixing main image. * Using new lemmy-isomorphic-ui with better javascript disabled. * Try to fix image uploads in federation test * Revert "Try to fix image uploads in federation test" This reverts commita2ddf2a90b
. * Fix post url federation * Adding some more tests, some still broken. * Don't need gitattributes anymore. * Update local federation test setup * Fixing tests. * Fixing travis build. * Fixing travis build, again. * Changing lemmy-isomorphic-ui to lemmy-ui * Error in travis build again. Co-authored-by: Felix Ableitner <me@nutomic.com>
100 lines
No EOL
2.3 KiB
SQL
100 lines
No EOL
2.3 KiB
SQL
-- Drop first
|
|
drop view community_view;
|
|
drop view community_aggregates_view;
|
|
drop view community_fast_view;
|
|
drop table community_aggregates_fast;
|
|
|
|
create view community_aggregates_view as
|
|
select
|
|
c.id,
|
|
c.name,
|
|
c.title,
|
|
c.icon,
|
|
c.banner,
|
|
c.description,
|
|
c.category_id,
|
|
c.creator_id,
|
|
c.removed,
|
|
c.published,
|
|
c.updated,
|
|
c.deleted,
|
|
c.nsfw,
|
|
c.actor_id,
|
|
c.local,
|
|
c.last_refreshed_at,
|
|
u.actor_id as creator_actor_id,
|
|
u.local as creator_local,
|
|
u.name as creator_name,
|
|
u.preferred_username as creator_preferred_username,
|
|
u.avatar as creator_avatar,
|
|
cat.name as category_name,
|
|
coalesce(cf.subs, 0) as number_of_subscribers,
|
|
coalesce(cd.posts, 0) as number_of_posts,
|
|
coalesce(cd.comments, 0) as number_of_comments,
|
|
hot_rank(cf.subs, c.published) as hot_rank
|
|
from community c
|
|
left join user_ u on c.creator_id = u.id
|
|
left join category cat on c.category_id = cat.id
|
|
left join (
|
|
select
|
|
p.community_id,
|
|
count(distinct p.id) as posts,
|
|
count(distinct ct.id) as comments
|
|
from post p
|
|
left join comment ct on p.id = ct.post_id
|
|
group by p.community_id
|
|
) cd on cd.community_id = c.id
|
|
left join (
|
|
select
|
|
community_id,
|
|
count(*) as subs
|
|
from community_follower
|
|
group by community_id
|
|
) cf on cf.community_id = c.id;
|
|
|
|
create view community_view as
|
|
select
|
|
cv.*,
|
|
us.user as user_id,
|
|
us.is_subbed::bool as subscribed
|
|
from community_aggregates_view cv
|
|
cross join lateral (
|
|
select
|
|
u.id as user,
|
|
coalesce(cf.community_id, 0) as is_subbed
|
|
from user_ u
|
|
left join community_follower cf on u.id = cf.user_id and cf.community_id = cv.id
|
|
) as us
|
|
|
|
union all
|
|
|
|
select
|
|
cv.*,
|
|
null as user_id,
|
|
null as subscribed
|
|
from community_aggregates_view cv;
|
|
|
|
-- The community fast table
|
|
|
|
create table community_aggregates_fast as select * from community_aggregates_view;
|
|
alter table community_aggregates_fast add primary key (id);
|
|
|
|
create view community_fast_view as
|
|
select
|
|
ac.*,
|
|
u.id as user_id,
|
|
(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
|
|
from user_ u
|
|
cross join (
|
|
select
|
|
ca.*
|
|
from community_aggregates_fast ca
|
|
) ac
|
|
|
|
union all
|
|
|
|
select
|
|
caf.*,
|
|
null as user_id,
|
|
null as subscribed
|
|
from community_aggregates_fast caf; |