From d2dc15330d480cc331ff4e7952e33e913005ee79 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Sat, 23 Dec 2023 14:33:24 -0700 Subject: [PATCH] Update replaceable_schema.sql --- replaceable_schema.sql | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/replaceable_schema.sql b/replaceable_schema.sql index e20833864..504eb7b9c 100644 --- a/replaceable_schema.sql +++ b/replaceable_schema.sql @@ -259,7 +259,7 @@ BEGIN -- Update aggregates for target target_aggregates_update_result (creator_id, creator_score_change) AS ( UPDATE - %1$s_aggregates AS aggregates + %1$s_aggregates AS target_aggregates SET score = score + added_upvotes - added_downvotes, upvotes = upvotes + added_upvotes, @@ -271,11 +271,21 @@ BEGIN FROM vote_group WHERE - aggregates.comment_id = vote_group.target_id + target_aggregates.comment_id = vote_group.target_id RETURNING %2$s, - added_upvotes - added_downvotes; - + added_upvotes - added_downvotes + ) + -- Update aggregates for target's creator + UPDATE + person_aggregates + SET + %1$s_score = creator_score_change; + FROM + target_aggregates_update_result + WHERE + person_aggregates.person_id = creator_id; + RETURN NULL; END $$; @@ -291,9 +301,9 @@ BEGIN END $a$; -CALL aggregates_from_like ('comment', '(SELECT creator_id FROM comment WHERE id = vote_group.target_id)'); +CALL aggregates_from_like ('comment', '(SELECT creator_id FROM comment WHERE id = vote_group.target_id LIMIT 1)'); -CALL aggregates_from_like ('post', 'creator_id'); +CALL aggregates_from_like ('post', 'target_aggregates.creator_id'); COMMIT;