mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-01 13:51:10 +00:00
stuff
This commit is contained in:
parent
7d8720ce10
commit
7162c13fac
1 changed files with 52 additions and 49 deletions
|
@ -146,30 +146,32 @@ BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
(thing_like).thing_id,
|
(thing_like).thing_id,
|
||||||
sum(count_diff) FILTER (WHERE (thing_like).score = 1) AS upvotes,
|
sum(count_diff) FILTER (WHERE (thing_like).score = 1) AS upvotes,
|
||||||
sum(count_diff) FILTER (WHERE (thing_like).score != 1) AS downvotes
|
sum(count_diff) FILTER (WHERE (thing_like).score != 1) AS downvotes
|
||||||
FROM
|
|
||||||
r.combine_transition_tables () AS (count_diff bigint, thing_like thing_like)
|
|
||||||
GROUP BY
|
|
||||||
(thing_like).thing_id) AS diff
|
|
||||||
WHERE
|
|
||||||
a.thing_id = diff.thing_id
|
|
||||||
RETURNING
|
|
||||||
creator_id_from_thing_aggregates (a.*) AS creator_id,
|
|
||||||
diff.upvotes - diff.downvotes AS score)
|
|
||||||
UPDATE
|
|
||||||
person_aggregates AS a
|
|
||||||
SET
|
|
||||||
thing_score = a.thing_score + diff.score
|
|
||||||
FROM (
|
|
||||||
SELECT
|
|
||||||
creator_id,
|
|
||||||
sum(score) AS score
|
|
||||||
FROM
|
FROM
|
||||||
target_diff
|
r.combine_transition_tables ()
|
||||||
|
AS (count_diff bigint,
|
||||||
|
thing_like thing_like)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
creator_id) AS diff
|
(thing_like).thing_id) AS diff
|
||||||
WHERE
|
WHERE
|
||||||
a.person_id = diff.creator_id;
|
a.thing_id = diff.thing_id
|
||||||
|
RETURNING
|
||||||
|
creator_id_from_thing_aggregates (a.*) AS creator_id,
|
||||||
|
diff.upvotes - diff.downvotes AS score)
|
||||||
|
UPDATE
|
||||||
|
person_aggregates AS a
|
||||||
|
SET
|
||||||
|
thing_score = a.thing_score + diff.score
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
creator_id,
|
||||||
|
sum(score) AS score
|
||||||
|
FROM
|
||||||
|
target_diff
|
||||||
|
GROUP BY
|
||||||
|
creator_id) AS diff
|
||||||
|
WHERE
|
||||||
|
a.person_id = diff.creator_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END $$;
|
END $$;
|
||||||
CALL r.create_triggers ('thing_like', 'thing_aggregates_from_like');
|
CALL r.create_triggers ('thing_like', 'thing_aggregates_from_like');
|
||||||
|
@ -196,14 +198,15 @@ BEGIN
|
||||||
(comment).local,
|
(comment).local,
|
||||||
sum(count_diff) AS comments
|
sum(count_diff) AS comments
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables () AS (count_diff bigint, comment comment)
|
r.combine_transition_tables ()
|
||||||
|
AS (count_diff bigint,
|
||||||
|
comment comment)
|
||||||
WHERE
|
WHERE
|
||||||
NOT ((comment).deleted
|
NOT ((comment).deleted OR (comment).removed)
|
||||||
OR (comment).removed)
|
|
||||||
GROUP BY
|
GROUP BY
|
||||||
GROUPING SETS ((comment)post_id,
|
GROUPING SETS ((comment).post_id,
|
||||||
(comment).creator_id,
|
(comment).creator_id,
|
||||||
(comment).local)
|
(comment).local)
|
||||||
),
|
),
|
||||||
unused_person_aggregates_update_result AS (
|
unused_person_aggregates_update_result AS (
|
||||||
UPDATE
|
UPDATE
|
||||||
|
@ -298,14 +301,15 @@ BEGIN
|
||||||
(post).local,
|
(post).local,
|
||||||
sum(count_diff) AS posts
|
sum(count_diff) AS posts
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables () AS (count_diff bigint, post post)
|
r.combine_transition_tables ()
|
||||||
|
AS (count_diff bigint,
|
||||||
|
post post)
|
||||||
WHERE
|
WHERE
|
||||||
NOT ((post).deleted
|
NOT ((post).deleted OR (post).removed)
|
||||||
OR (post).removed)
|
|
||||||
GROUP BY
|
GROUP BY
|
||||||
GROUPING SETS ((post).community_id,
|
GROUPING SETS ((post).community_id,
|
||||||
(post).creator_id,
|
(post).creator_id,
|
||||||
(post).local)
|
(post).local)
|
||||||
),
|
),
|
||||||
unused_person_aggregates_update_result AS (
|
unused_person_aggregates_update_result AS (
|
||||||
UPDATE
|
UPDATE
|
||||||
|
@ -353,11 +357,9 @@ BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
sum(count_diff) AS communities
|
sum(count_diff) AS communities
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables () AS (count_diff bigint, community community)
|
r.combine_transition_tables ()
|
||||||
WHERE
|
AS (count_diff bigint, community community)
|
||||||
(community).local
|
WHERE (community).local AND NOT ((community).deleted OR (community).removed)) AS diff;
|
||||||
AND NOT ((community).deleted
|
|
||||||
OR (community).removed)) AS diff;
|
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END
|
END
|
||||||
$$;
|
$$;
|
||||||
|
@ -377,9 +379,9 @@ BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
sum(count_diff) AS users
|
sum(count_diff) AS users
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables () AS (count_diff bigint, person person)
|
r.combine_transition_tables ()
|
||||||
WHERE
|
AS (count_diff bigint, person person)
|
||||||
(person).local) AS diff;
|
WHERE (person).local) AS diff;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END
|
END
|
||||||
$$;
|
$$;
|
||||||
|
@ -448,15 +450,16 @@ BEGIN
|
||||||
(community_follower).community_id,
|
(community_follower).community_id,
|
||||||
sum(count_diff) AS subscribers
|
sum(count_diff) AS subscribers
|
||||||
FROM
|
FROM
|
||||||
r.combine_transition_tables () AS (count_diff bigint, community_follower community_follower)
|
r.combine_transition_tables ()
|
||||||
|
AS (count_diff bigint, community_follower community_follower)
|
||||||
WHERE (
|
WHERE (
|
||||||
SELECT
|
SELECT
|
||||||
local
|
local
|
||||||
FROM
|
FROM
|
||||||
community
|
community
|
||||||
WHERE
|
WHERE
|
||||||
community.id = (community_follower).community_id
|
community.id = (community_follower).community_id
|
||||||
LIMIT 1)
|
LIMIT 1)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
(community_follower).community_id) AS diff
|
(community_follower).community_id) AS diff
|
||||||
WHERE
|
WHERE
|
||||||
|
|
Loading…
Reference in a new issue