From a4c1756707b05c26f1e66ef48159eef5d2e3d106 Mon Sep 17 00:00:00 2001 From: pory-gone <83127821+pory-gone@users.noreply.github.com> Date: Thu, 4 Dec 2025 19:38:39 +0100 Subject: [PATCH 1/2] fix wrong top boost --- api/resolvers/item.js | 60 +++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/api/resolvers/item.js b/api/resolvers/item.js index a4a4b531e..dd085a428 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -29,6 +29,7 @@ import { verifyHmac } from './wallet' import { parse } from 'tldts' import { shuffleArray } from '@/lib/rand' import pay from '../payIn' +import { Prisma } from '@prisma/client' function commentsOrderByClause (me, models, sort) { const sharedSortsArray = [] @@ -758,30 +759,57 @@ export default { return await models.item.count({ where }) + 1 }, boostPosition: async (parent, { id, sub, boost = 0 }, { models, me }) => { - const where = { - boost: { gte: boost }, - status: 'ACTIVE', - deletedAt: null, - outlawed: false, - parentId: null - } - if (id) { - where.id = { not: Number(id) } + const currentUser = me ? await models.user.findUnique({ where: { id: me.id } }) : null + const showNsfw = currentUser ? currentUser.nsfwMode : false + const homeAggResult = await models.$queryRaw` + SELECT COUNT(i.id)::INTEGER as count, MAX(i.boost)::INTEGER as "maxBoost" + FROM "Item" i + LEFT JOIN "Sub" s ON s.name = i."subName" + WHERE i.boost >= ${boost} + AND i.status = 'ACTIVE' + AND i."deletedAt" IS NULL + AND i.outlawed = false + AND i."parentId" IS NULL + ${id ? Prisma.sql`AND i.id <> ${Number(id)}` : Prisma.empty} + ${sub + ? Prisma.empty + : (showNsfw + ? Prisma.empty + : Prisma.sql`AND (s.nsfw = false OR s.nsfw IS NULL)` + ) + } + ${me && !sub + ? Prisma.sql`AND NOT EXISTS ( + SELECT 1 FROM "MuteSub" + WHERE "MuteSub"."userId" = ${me.id} + AND "MuteSub"."subName" = i."subName" + )` + : Prisma.empty} + ${me + ? Prisma.sql`AND NOT EXISTS ( + SELECT 1 FROM "Mute" + WHERE "Mute"."muterId" = ${me.id} + AND "Mute"."mutedId" = i."userId" + )` + : Prisma.empty} + ` + const homeAgg = { + _count: { id: homeAggResult[0]?.count || 0 }, + _max: { boost: homeAggResult[0]?.maxBoost || 0 } } - const homeAgg = await models.item.aggregate({ - _count: { id: true }, - _max: { boost: true }, - where - }) - let subAgg if (sub) { subAgg = await models.item.aggregate({ _count: { id: true }, _max: { boost: true }, where: { - ...where, + boost: { gte: boost }, + status: 'ACTIVE', + deletedAt: null, + outlawed: false, + parentId: null, + ...(id && { id: { not: Number(id) } }), subName: sub } }) From e3da4f49107c558ecdb688593185508e01b57744 Mon Sep 17 00:00:00 2001 From: pory-gone <83127821+pory-gone@users.noreply.github.com> Date: Sat, 6 Dec 2025 18:08:51 +0100 Subject: [PATCH 2/2] alternative fix proposal on filters --- api/resolvers/item.js | 62 +++++++++++++------------------------------ 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/api/resolvers/item.js b/api/resolvers/item.js index dd085a428..0d73a31af 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -29,7 +29,6 @@ import { verifyHmac } from './wallet' import { parse } from 'tldts' import { shuffleArray } from '@/lib/rand' import pay from '../payIn' -import { Prisma } from '@prisma/client' function commentsOrderByClause (me, models, sort) { const sharedSortsArray = [] @@ -759,44 +758,24 @@ export default { return await models.item.count({ where }) + 1 }, boostPosition: async (parent, { id, sub, boost = 0 }, { models, me }) => { - const currentUser = me ? await models.user.findUnique({ where: { id: me.id } }) : null - const showNsfw = currentUser ? currentUser.nsfwMode : false - const homeAggResult = await models.$queryRaw` - SELECT COUNT(i.id)::INTEGER as count, MAX(i.boost)::INTEGER as "maxBoost" - FROM "Item" i - LEFT JOIN "Sub" s ON s.name = i."subName" - WHERE i.boost >= ${boost} - AND i.status = 'ACTIVE' - AND i."deletedAt" IS NULL - AND i.outlawed = false - AND i."parentId" IS NULL - ${id ? Prisma.sql`AND i.id <> ${Number(id)}` : Prisma.empty} - ${sub - ? Prisma.empty - : (showNsfw - ? Prisma.empty - : Prisma.sql`AND (s.nsfw = false OR s.nsfw IS NULL)` - ) - } - ${me && !sub - ? Prisma.sql`AND NOT EXISTS ( - SELECT 1 FROM "MuteSub" - WHERE "MuteSub"."userId" = ${me.id} - AND "MuteSub"."subName" = i."subName" - )` - : Prisma.empty} - ${me - ? Prisma.sql`AND NOT EXISTS ( - SELECT 1 FROM "Mute" - WHERE "Mute"."muterId" = ${me.id} - AND "Mute"."mutedId" = i."userId" - )` - : Prisma.empty} - ` - const homeAgg = { - _count: { id: homeAggResult[0]?.count || 0 }, - _max: { boost: homeAggResult[0]?.maxBoost || 0 } + const where = { + boost: { gte: boost }, + status: 'ACTIVE', + deletedAt: null, + outlawed: false, + parentId: null, + pinId: null, + bio: false } + if (id) { + where.id = { not: Number(id) } + } + + const homeAgg = await models.item.aggregate({ + _count: { id: true }, + _max: { boost: true }, + where + }) let subAgg if (sub) { @@ -804,12 +783,7 @@ export default { _count: { id: true }, _max: { boost: true }, where: { - boost: { gte: boost }, - status: 'ACTIVE', - deletedAt: null, - outlawed: false, - parentId: null, - ...(id && { id: { not: Number(id) } }), + ...where, subName: sub } })