🐛 (analytics) Fix multi usage query timeout
This commit is contained in:
@@ -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}
|
||||||
@@ -86,4 +85,3 @@ export const Edges = ({
|
|||||||
</marker>
|
</marker>
|
||||||
</chakra.svg>
|
</chakra.svg>
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user