From ebb3da07d138d00c600657beebaaec4c386d0e9c Mon Sep 17 00:00:00 2001 From: keyan Date: Mon, 31 Jan 2022 09:56:21 -0600 Subject: [PATCH] fix duplicate notifications to your own descendant of a descendant --- api/resolvers/notifications.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/resolvers/notifications.js b/api/resolvers/notifications.js index 0adf3130..ccc0eadf 100644 --- a/api/resolvers/notifications.js +++ b/api/resolvers/notifications.js @@ -64,13 +64,13 @@ export default { // queries ... we only ever need at most LIMIT+current offset in the child queries to // have enough items to return in the union const notifications = await models.$queryRaw(` - (SELECT "Item".id::TEXT, "Item".created_at AS "sortTime", NULL as "earnedSats", + (SELECT DISTINCT ON ("Item".created_at, "Item".id) "Item".id::TEXT, "Item".created_at AS "sortTime", NULL as "earnedSats", 'Reply' AS type FROM "Item" JOIN "Item" p ON "Item".path <@ p.path WHERE p."userId" = $1 AND "Item"."userId" <> $1 AND "Item".created_at <= $2 - ORDER BY "Item".created_at DESC + ORDER BY "Item".created_at DESC, "Item".id DESC LIMIT ${LIMIT}+$3) UNION ALL (SELECT "Item".id::TEXT, MAX("ItemAct".created_at) AS "sortTime",