fix lastCommentAt denorm

This commit is contained in:
keyan 2024-07-02 09:26:40 -05:00
parent 63e60fe2bc
commit 9145f290dc
1 changed files with 2 additions and 1 deletions

View File

@ -197,7 +197,7 @@ export async function onPaid ({ invoice, id }, context) {
// TODO: referals for boost // TODO: referals for boost
if (item.parentId) { if (item.parentId) {
// denormalize ncomments and "weightedComments" for ancestors, and insert into reply table // denormalize ncomments, lastCommentAt, and "weightedComments" for ancestors, and insert into reply table
await tx.$executeRaw` await tx.$executeRaw`
WITH comment AS ( WITH comment AS (
SELECT * SELECT *
@ -206,6 +206,7 @@ export async function onPaid ({ invoice, id }, context) {
), ancestors AS ( ), ancestors AS (
UPDATE "Item" UPDATE "Item"
SET ncomments = "Item".ncomments + 1, SET ncomments = "Item".ncomments + 1,
"lastCommentAt" = now(),
"weightedComments" = "Item"."weightedComments" + "weightedComments" = "Item"."weightedComments" +
CASE WHEN comment."userId" = "Item"."userId" THEN 0 ELSE ${item.user.trust}::FLOAT END CASE WHEN comment."userId" = "Item"."userId" THEN 0 ELSE ${item.user.trust}::FLOAT END
FROM comment FROM comment