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,74 +16,72 @@ export const Edges = ({
edges, edges,
answersCounts, answersCounts,
onUnlockProPlanClick, onUnlockProPlanClick,
}: Props) => { }: Props) => (
return ( <chakra.svg
<chakra.svg width="full"
width="full" height="full"
height="full" overflow="visible"
overflow="visible" pos="absolute"
pos="absolute" left="0"
left="0" top="0"
top="0" shapeRendering="geometricPrecision"
shapeRendering="geometricPrecision" >
<DrawingEdge />
{edges.map((edge) => (
<Edge key={edge.id} edge={edge} />
))}
{answersCounts?.map((answerCount) => (
<DropOffEdge
key={answerCount.groupId}
answersCounts={answersCounts}
groupId={answerCount.groupId}
onUnlockProPlanClick={onUnlockProPlanClick}
/>
))}
<marker
id={'arrow'}
refX="8"
refY="4"
orient="auto"
viewBox="0 0 20 20"
markerUnits="userSpaceOnUse"
markerWidth="20"
markerHeight="20"
> >
<DrawingEdge /> <path
{edges.map((edge) => ( d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z"
<Edge key={edge.id} edge={edge} /> fill={colors.gray[400]}
))} />
{answersCounts?.slice(1)?.map((answerCount) => ( </marker>
<DropOffEdge <marker
key={answerCount.groupId} id={'blue-arrow'}
answersCounts={answersCounts} refX="8"
groupId={answerCount.groupId} refY="4"
onUnlockProPlanClick={onUnlockProPlanClick} orient="auto"
/> viewBox="0 0 20 20"
))} markerUnits="userSpaceOnUse"
<marker markerWidth="20"
id={'arrow'} markerHeight="20"
refX="8" >
refY="4" <path
orient="auto" d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z"
viewBox="0 0 20 20" fill={colors.blue[400]}
markerUnits="userSpaceOnUse" />
markerWidth="20" </marker>
markerHeight="20" <marker
> id={'red-arrow'}
<path refX="8"
d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z" refY="4"
fill={colors.gray[400]} orient="auto"
/> viewBox="0 0 20 20"
</marker> markerUnits="userSpaceOnUse"
<marker markerWidth="20"
id={'blue-arrow'} markerHeight="20"
refX="8" >
refY="4" <path
orient="auto" d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z"
viewBox="0 0 20 20" fill="#e53e3e"
markerUnits="userSpaceOnUse" />
markerWidth="20" </marker>
markerHeight="20" </chakra.svg>
> )
<path
d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z"
fill={colors.blue[400]}
/>
</marker>
<marker
id={'red-arrow'}
refX="8"
refY="4"
orient="auto"
viewBox="0 0 20 20"
markerUnits="userSpaceOnUse"
markerWidth="20"
markerHeight="20"
>
<path
d="M7.07138888,5.50174526 L2.43017246,7.82235347 C1.60067988,8.23709976 0.592024983,7.90088146 0.177278692,7.07138888 C0.0606951226,6.83822174 0,6.58111307 0,6.32042429 L0,1.67920787 C0,0.751806973 0.751806973,0 1.67920787,0 C1.93989666,0 2.19700532,0.0606951226 2.43017246,0.177278692 L7,3 C7.82949258,3.41474629 8.23709976,3.92128809 7.82235347,4.75078067 C7.6598671,5.07575341 7.39636161,5.33925889 7.07138888,5.50174526 Z"
fill="#e53e3e"
/>
</marker>
</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) },
}) },
return { groupId: group.id, totalAnswers } _count: { _all: true },
} })
) return res.status(200).send({
) answersCounts: answersCounts.map((answer) => ({
return res.status(200).send({ answersCounts }) groupId: answer.groupId,
totalAnswers: answer._count._all,
})),
})
} }
return methodNotAllowed(res) return methodNotAllowed(res)
} }