fix duplicate notifications to your own descendant of a descendant

This commit is contained in:
keyan 2022-01-31 09:56:21 -06:00
parent 751abaa1ad
commit ebb3da07d1
1 changed files with 2 additions and 2 deletions

View File

@ -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",