]> Untitled Git - lemmy.git/blob - migrations/2021-08-16-004209_fix_remove_bots_from_aggregates/down.sql
feat: re-added captcha checks (#3289)
[lemmy.git] / migrations / 2021-08-16-004209_fix_remove_bots_from_aggregates / down.sql
1 create or replace function community_aggregates_activity(i text)
2 returns table(count_ bigint, community_id_ integer)
3 language plpgsql
4 as
5 $$
6 begin
7   return query 
8   select count(*), community_id
9   from (
10     select c.creator_id, p.community_id from comment c
11     inner join post p on c.post_id = p.id
12     where c.published > ('now'::timestamp - i::interval)
13     union
14     select p.creator_id, p.community_id from post p
15     where p.published > ('now'::timestamp - i::interval)  
16   ) a
17   group by community_id;
18 end;
19 $$;
20
21 create or replace function site_aggregates_activity(i text) returns integer
22     language plpgsql
23     as $$
24 declare
25    count_ integer;
26 begin
27   select count(*)
28   into count_
29   from (
30     select c.creator_id from comment c
31     inner join person u on c.creator_id = u.id
32     where c.published > ('now'::timestamp - i::interval) 
33     and u.local = true
34     union
35     select p.creator_id from post p
36     inner join person u on p.creator_id = u.id
37     where p.published > ('now'::timestamp - i::interval)
38     and u.local = true
39   ) a;
40   return count_;
41 end;
42 $$;