diff --git a/api/paidAction/itemCreate.js b/api/paidAction/itemCreate.js index be7a77d6..fb4ae550 100644 --- a/api/paidAction/itemCreate.js +++ b/api/paidAction/itemCreate.js @@ -20,18 +20,15 @@ export async function getBaseCost ({ models, bio, parentId, subName }) { if (parentId) { // the subname is stored in the root item of the thread - const parent = await models.item.findFirst({ - where: { id: Number(parentId) }, - include: { - root: { include: { sub: true } }, - sub: true - } - }) + const [sub] = await models.$queryRaw` + SELECT s."replyCost" + FROM "Item" i + LEFT JOIN "Item" r ON r.id = i."rootId" + LEFT JOIN "Sub" s ON s.name = COALESCE(r."subName", i."subName") + WHERE i.id = ${Number(parentId)}` - const root = parent.root ?? parent - - if (!root.sub) return DEFAULT_ITEM_COST - return satsToMsats(root.sub.replyCost) + if (!sub) return DEFAULT_ITEM_COST + return satsToMsats(sub.replyCost) } const sub = await models.sub.findUnique({ where: { name: subName } }) diff --git a/fragments/items.js b/fragments/items.js index c9c2a8da..c58de13a 100644 --- a/fragments/items.js +++ b/fragments/items.js @@ -108,6 +108,7 @@ export const ITEM_FULL_FIELDS = gql` moderated meMuteSub meSubscription + replyCost } } forwards {