Skip to content

Commit 9aad2fd

Browse files
authored
Merge pull request #1963 from stackernews/fix-item-cost
Fix item cost in details
2 parents d8c6041 + ed9fa5f commit 9aad2fd

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

api/paidAction/itemCreate.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ export async function getBaseCost ({ models, bio, parentId, subName }) {
2020

2121
if (parentId) {
2222
// the subname is stored in the root item of the thread
23-
const parent = await models.item.findFirst({
24-
where: { id: Number(parentId) },
25-
include: {
26-
root: { include: { sub: true } },
27-
sub: true
28-
}
29-
})
30-
31-
const root = parent.root ?? parent
32-
33-
if (!root.sub) return DEFAULT_ITEM_COST
34-
return satsToMsats(root.sub.replyCost)
23+
const [sub] = await models.$queryRaw`
24+
SELECT s."replyCost"
25+
FROM "Item" i
26+
LEFT JOIN "Item" r ON r.id = i."rootId"
27+
LEFT JOIN "Sub" s ON s.name = COALESCE(r."subName", i."subName")
28+
WHERE i.id = ${Number(parentId)}`
29+
30+
if (!sub) return DEFAULT_ITEM_COST
31+
return satsToMsats(sub.replyCost)
3532
}
3633

3734
const sub = await models.sub.findUnique({ where: { name: subName } })

fragments/items.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export const ITEM_FULL_FIELDS = gql`
108108
moderated
109109
meMuteSub
110110
meSubscription
111+
replyCost
111112
}
112113
}
113114
forwards {

0 commit comments

Comments
 (0)