tRPC queries&mutations really slow on Vercel+Planetscale deployment

Hello! I deployed my T3 app to vercel and the DB to Planetscale, and I am seeing some incredibly slow speeds on the queries/mutations for tRPC. Take this mutation for following a user for example:
follow: authedProcedure
.input(
z.object({
id: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const userId = ctx.session.user?.id;
if (!userId) throw new TRPCError({ code: 'UNAUTHORIZED' });
const user = await ctx.prisma.user.findUniqueOrThrow({ where: { id: input.id } });
const userFollow = await ctx.prisma.userFollow.upsert({
where: { followerUserId_followTargetUserId: { followerUserId: userId, followTargetUserId: user.id } },
create: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
update: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
});
return {
userFollow,
};
}),
follow: authedProcedure
.input(
z.object({
id: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const userId = ctx.session.user?.id;
if (!userId) throw new TRPCError({ code: 'UNAUTHORIZED' });
const user = await ctx.prisma.user.findUniqueOrThrow({ where: { id: input.id } });
const userFollow = await ctx.prisma.userFollow.upsert({
where: { followerUserId_followTargetUserId: { followerUserId: userId, followTargetUserId: user.id } },
create: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
update: { followerUser: { connect: { id: userId } }, followTargetUser: { connect: { id: user.id } } },
});
return {
userFollow,
};
}),
This mutation averages around 800-1000 ms on Vercel+Planetscale, while it locally never takes more than 100ms. I would love some insight into what I might need to look into. Maybe something is misconfigured? Both Planetscale and Vercel are located in same region (eu-west). This problem is for all tRPC queries/mutations 😬 Thank you for reading
2 Replies
O2K
O2K•2y ago
Looking into PlanetScale and the queries themselves are very fast 🤔
Scot
Scot•2y ago
how long are the queries to planetscale tho
Want results from more Discord servers?
Add your server