🐛 (analytics) Fix multi usage query timeout
This commit is contained in:
@ -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>
|
||||
)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user