mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 04:41:19 +00:00
Nutomic
56322c75f0
* Read community follower count from home instance (fixes #1440) * fmt * prettier * fix tests * fmt * rename fn * fmt * Run prettier * increase timeout * ci --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: Dessalines <tyhou13@gmx.com>
34 lines
921 B
PL/PgSQL
34 lines
921 B
PL/PgSQL
-- The subscriber count should only be updated for local communities. For remote
|
|
-- communities it is read over federation from the origin instance.
|
|
CREATE OR REPLACE FUNCTION community_aggregates_subscriber_count ()
|
|
RETURNS TRIGGER
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
BEGIN
|
|
IF (TG_OP = 'INSERT') THEN
|
|
UPDATE
|
|
community_aggregates
|
|
SET
|
|
subscribers = subscribers + 1
|
|
FROM
|
|
community
|
|
WHERE
|
|
community.id = community_id
|
|
AND community.local
|
|
AND community_id = NEW.community_id;
|
|
ELSIF (TG_OP = 'DELETE') THEN
|
|
UPDATE
|
|
community_aggregates
|
|
SET
|
|
subscribers = subscribers - 1
|
|
FROM
|
|
community
|
|
WHERE
|
|
community.id = community_id
|
|
AND community.local
|
|
AND community_id = OLD.community_id;
|
|
END IF;
|
|
RETURN NULL;
|
|
END
|
|
$$;
|
|
|