Vercel Edge Runtime + Supabase + Drizzle, 15 seconds server lags + Trpc

When deploying on vercel with lambda everything is extra smooth. With vercel edge runtime a lot of things are not quite working One of those things are my transactions. The db < - > server trip is very fast. but the server < - > client takes 15seconds + Am I doing something wrong with this transaction?
await ctx.db.transaction(async (db) => {
const board = await db
.insert(boards)
.values({
name: input.name,
twitchUsername: input.twitchUsername,
youtubeChannelId: input.youtubeChannelId,
id: input.id,
slug: input.slug,
})
.returning();

console.timeLog("addNewBoard", { board });
const newValue = board[0] || null;

if (!newValue) {
db.rollback();

return "success";
}

await db.insert(boardOwnerships).values({
boardId: newValue.id,
profileId: ctx.user.id,
});
console.timeLog("addNewBoard", "board query done");

return "success";
});
console.timeEnd("addNewBoard");

return "success";
await ctx.db.transaction(async (db) => {
const board = await db
.insert(boards)
.values({
name: input.name,
twitchUsername: input.twitchUsername,
youtubeChannelId: input.youtubeChannelId,
id: input.id,
slug: input.slug,
})
.returning();

console.timeLog("addNewBoard", { board });
const newValue = board[0] || null;

if (!newValue) {
db.rollback();

return "success";
}

await db.insert(boardOwnerships).values({
boardId: newValue.id,
profileId: ctx.user.id,
});
console.timeLog("addNewBoard", "board query done");

return "success";
});
console.timeEnd("addNewBoard");

return "success";
1. When I remove the transaction and write the same code without it, it works as expected 2. Works perfectly on lambda 3. works perfectly locally
5 Replies
Mykhailo
Mykhailo9mo ago
Hello, @Jaaneek! You should use db instead of ctx.db here
No description
Jaaneek
JaaneekOP9mo ago
Ohh sorry, I copy pasted it with a mistake. I had db.insert in there before. Still the same problem Edit: fixed it in the example
No description
Jaaneek
JaaneekOP9mo ago
@solo can you spot any other mistakes? ❤️
Mykhailo
Mykhailo9mo ago
@Jaaneek honestly, I can't spot any mistakes then:))
Jaaneek
JaaneekOP9mo ago
Yeah I think supabase & edge vercel are just not ready to work together and something in drizzle transaction breaks them 😦 Thanks for checking it out!
Want results from more Discord servers?
Add your server