Skip to content

Commit ed9fa5f

Browse files
committed
fix fragment when comment visited directly + one db dip
1 parent 65b1db2 commit ed9fa5f

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

api/paidAction/itemCreate.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@ 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-
// XXX Prisma does not support case-insensitive joins on CITEXT column
34-
// so we fetch the territory in a separate query
35-
const sub = await models.sub.findUnique({
36-
where: { name: root.subName }
37-
})
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)}`
3829

3930
if (!sub) return DEFAULT_ITEM_COST
4031
return satsToMsats(sub.replyCost)

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)