BA
Better Auth•3mo ago
PIat

Slow API

Hello! When I try try create an organization and update it immediately, the update either doesn't run at all or it takes about 20 seconds. What is the reason for this slowdown?
10 Replies
PIat
PIatOP•3mo ago
An example
const org = await auth.api.createOrganization({
headers,
body: {
name: tempOrgId,
slug: tempOrgId,
},
})


await auth.api.updateOrganization({
headers: request.headers,
body: {
data: {
name: orgId,
slug: orgId,
},
},
})
const org = await auth.api.createOrganization({
headers,
body: {
name: tempOrgId,
slug: tempOrgId,
},
})


await auth.api.updateOrganization({
headers: request.headers,
body: {
data: {
name: orgId,
slug: orgId,
},
},
})
Bump
bekacru
bekacru•3mo ago
you should check if there are any problem with your db connection. all the api does is just call insert to db
PIat
PIatOP•3mo ago
Thank you for the answer! I also expected it to be the case, but this doesn't happen anywhere in my postgres connection outside of this usecase. But if you say the library doesn't introduce additional rate limits, it must be the case
bekacru
bekacru•3mo ago
all the library does is just insert those data to your database. What adapter are you using?
PIat
PIatOP•3mo ago
The Prisma adapter
prismaAdapter(prisma, {
provider: 'postgresql',
}),
prismaAdapter(prisma, {
provider: 'postgresql',
}),
These manipulations are taking place in an interactive transaction prisma.$transaction I can confirm no slowdowns are happening anywhere else in the database. Even running dozens of queries a second doesn't introduce any noticeable delay, only this part It could be a red herring and the problem could actually be with the getSession function being slow on my end, since having it in the first place slows things down dramatically
Unknown User
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
PIat
PIatOP•3mo ago
It's very illogical that it would be slow, but it's what I'm seeing. Without the introduction of better-auth client the app works as it should. After making a few request, the app hangs
Unknown User
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
PIat
PIatOP•3mo ago
Unfortunately not 🫠
bekacru
bekacru•3mo ago
also make sure to index the token field in your session table

Did you find this page helpful?