2
0

🐛 (analytics) Fix multi usage query timeout

This commit is contained in:
Baptiste Arnaud
2022-10-17 08:19:50 +02:00
parent 020a37c1f3
commit 9cb7f8cd96
2 changed files with 84 additions and 83 deletions

View File

@@ -16,8 +16,7 @@ export const Edges = ({
edges, edges,
answersCounts, answersCounts,
onUnlockProPlanClick, onUnlockProPlanClick,
}: Props) => { }: Props) => (
return (
<chakra.svg <chakra.svg
width="full" width="full"
height="full" height="full"
@@ -31,7 +30,7 @@ export const Edges = ({
{edges.map((edge) => ( {edges.map((edge) => (
<Edge key={edge.id} edge={edge} /> <Edge key={edge.id} edge={edge} />
))} ))}
{answersCounts?.slice(1)?.map((answerCount) => ( {answersCounts?.map((answerCount) => (
<DropOffEdge <DropOffEdge
key={answerCount.groupId} key={answerCount.groupId}
answersCounts={answersCounts} answersCounts={answersCounts}
@@ -85,5 +84,4 @@ export const Edges = ({
/> />
</marker> </marker>
</chakra.svg> </chakra.svg>
) )
}

View File

@@ -15,19 +15,22 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
where: canReadTypebot(typebotId, user), where: canReadTypebot(typebotId, user),
include: { publishedTypebot: true }, include: { publishedTypebot: true },
}) })
if (!typebot) return res.status(404).send({ answersCounts: [] }) const publishedTypebot =
const answersCounts: { groupId: string; totalAnswers: number }[] = typebot?.publishedTypebot as unknown as PublicTypebot
await Promise.all( if (!publishedTypebot) return res.status(404).send({ answersCounts: [] })
(typebot.publishedTypebot as unknown as PublicTypebot).groups.map( const answersCounts = await prisma.answer.groupBy({
async (group) => { by: ['groupId'],
const totalAnswers = await prisma.answer.count({ where: {
where: { groupId: group.id }, groupId: { in: publishedTypebot.groups.map((g) => g.id) },
},
_count: { _all: true },
})
return res.status(200).send({
answersCounts: answersCounts.map((answer) => ({
groupId: answer.groupId,
totalAnswers: answer._count._all,
})),
}) })
return { groupId: group.id, totalAnswers }
}
)
)
return res.status(200).send({ answersCounts })
} }
return methodNotAllowed(res) return methodNotAllowed(res)
} }