Next.js Discord

Discord Forum

api route performance

Unanswered
Cinnamon posted this in #help-forum
Open in Discord
CinnamonOP
wanna know the best way to optmize this route

its currenlty taking about 3 sec in avg just to do these basic things i will have to add batch upload thing in here so that would take some time obv but rn as of this its taking so much time to compile

8 Replies

Snow Goose
The biggest bottleneck is probably not the transformation itself, but doing everything synchronously inside one API request, plus repeated logging and repeated mapping loops. I would first clean the route, precompute the mapping rules, select only required DB fields, and then move the bulk contact processing into a background job with chunked inserts. That will make the import scalable and avoid timeout problems when batch upload is added.
are you in dev mode or production? like if in dev things are generally slowe as different priorities
also yeah depending on where your database is, you have quite the sum of round trips
@riský are you in dev mode or production? like if in dev things are generally slowe as different priorities
CinnamonOP
its dev mode but still i havnt added core functionality to it and yet its taking so long
also i think the overall workflow is messed up im keeping the entire data or csv file in the routes which is not being used
@Cinnamon its dev mode but still i havnt added core functionality to it and yet its taking so long
yes, never use dev as any indication of speed. its never going to be as fast as production as it doesnt have as chaotic as a build step as its meant to be fast enough