enhance item related query perf
This commit is contained in:
parent
183201a1b8
commit
9afbe0abd8
@ -902,19 +902,6 @@ export default {
|
|||||||
|
|
||||||
return count
|
return count
|
||||||
},
|
},
|
||||||
boost: async (item, args, { models }) => {
|
|
||||||
const { sum: { msats } } = await models.itemAct.aggregate({
|
|
||||||
sum: {
|
|
||||||
msats: true
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
itemId: Number(item.id),
|
|
||||||
act: 'BOOST'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return (msats && msatsToSats(msats)) || 0
|
|
||||||
},
|
|
||||||
wvotes: async (item) => {
|
wvotes: async (item) => {
|
||||||
return item.weightedVotes - item.weightedDownVotes
|
return item.weightedVotes - item.weightedDownVotes
|
||||||
},
|
},
|
||||||
@ -1152,7 +1139,7 @@ export const SELECT =
|
|||||||
"Item".text, "Item".url, "Item"."bounty", "Item"."userId", "Item"."fwdUserId", "Item"."parentId",
|
"Item".text, "Item".url, "Item"."bounty", "Item"."userId", "Item"."fwdUserId", "Item"."parentId",
|
||||||
"Item"."pinId", "Item"."maxBid", "Item"."rootId",
|
"Item"."pinId", "Item"."maxBid", "Item"."rootId",
|
||||||
"Item".company, "Item".location, "Item".remote, "Item"."deletedAt",
|
"Item".company, "Item".location, "Item".remote, "Item"."deletedAt",
|
||||||
"Item"."subName", "Item".status, "Item"."uploadId", "Item"."pollCost",
|
"Item"."subName", "Item".status, "Item"."uploadId", "Item"."pollCost", "Item".boost,
|
||||||
"Item".msats, "Item".ncomments, "Item"."commentMsats", "Item"."lastCommentAt", "Item"."weightedVotes",
|
"Item".msats, "Item".ncomments, "Item"."commentMsats", "Item"."lastCommentAt", "Item"."weightedVotes",
|
||||||
"Item"."weightedDownVotes", "Item".freebie, "Item"."otsHash", "Item"."bountyPaidTo", ltree2text("Item"."path") AS "path"`
|
"Item"."weightedDownVotes", "Item".freebie, "Item"."otsHash", "Item"."bountyPaidTo", ltree2text("Item"."path") AS "path"`
|
||||||
|
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Bookmark.created_at_index" ON "Bookmark"("created_at");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "ItemAct.itemId_act_userId_index" ON "ItemAct"("itemId", "act", "userId");
|
@ -418,6 +418,7 @@ model ItemAct {
|
|||||||
@@index([userId])
|
@@index([userId])
|
||||||
@@index([act])
|
@@index([act])
|
||||||
@@index([createdAt])
|
@@index([createdAt])
|
||||||
|
@@index([itemId, act, userId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model Mention {
|
model Mention {
|
||||||
@ -532,6 +533,7 @@ model Bookmark {
|
|||||||
item Item @relation(fields: [itemId], references: [id])
|
item Item @relation(fields: [itemId], references: [id])
|
||||||
itemId Int
|
itemId Int
|
||||||
createdAt DateTime @default(now()) @map(name: "created_at")
|
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||||
|
|
||||||
@@id([userId, itemId])
|
@@id([userId, itemId])
|
||||||
@@index([createdAt])
|
@@index([createdAt])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user