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

View File

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