Next.js Discord

Discord Forum

SSR / Server Side Fetching 4+ seconds on production

Unanswered
Yellowstripe scad posted this in #help-forum
Open in Discord
Yellowstripe scadOP
My code is attached, I am fetching classes from my database which has assignments inside of it. Then, the assignments and classes are mapped in a seperate component that is inside the skeleton. Assignments are mapped inside the classes map. I'm not sure how to make this lightning fast but it sometimes takes 5 seconds to load even on production.

34 Replies

Yellowstripe scadOP
🙏 ill try that rq
and btw, how many rows are there ?
Yellowstripe scadOP
like table objects?
@`${ViNoS}` yes
Yellowstripe scadOP
had to zoom out a bit but I hope this is what you mean
should help visualize the objects
Yellowstripe scadOP
yea
@`${ViNoS}` i see that ain't much data
Yellowstripe scadOP
ok here, usually it takes longer on production. also, it takes the longest on the startup I think of the database server
in prod on first load it can take up to 5 seconds
maybe im fine with it taking a good amount of time on the first load but how can I cache the data so it doesnt have to reload unless something changed in the last what minute or two?
is this a database problem where I should invest in a quicker db or something
@Yellowstripe scad ok here, usually it takes longer on production. also, it takes the longest on the startup I think of the database server
first 600ms seems concerning, try and ask in prisma server if that is fine
but anyways let's ignore it for now, other calls are only 150ms
that's far from 5s
btw i don't see here that it takes 5s
but ty for helping
is there a way to cache the data
?
yes there is
@`${ViNoS}` yes there is
Yellowstripe scadOP
could you link some docs for that
here it is
I never used it, i only cached fetch requests
but if you got stuck ask again i might be able to help
@`${ViNoS}` I never used it, i only cached fetch requests but if you got stuck ask again i might be able to help
Yellowstripe scadOP
ok tysm, would it be easier to just fetch on client component using tanstack query with caching and call it a day?
@Yellowstripe scad ok tysm, would it be easier to just fetch on client component using tanstack query with caching and call it a day?
it is better to fetch on the server side
however that depends on the data and the auth
for example if the data requires the user to be authenticated you might not be able to fetch it server side (depending on how and where you are implimening the auth)
@`${ViNoS}` it is better to fetch on the server side however that depends on the data and the auth for example if the data requires the user to be authenticated you might not be able to fetch it server side (depending on how and where you are implimening the auth)
Yellowstripe scadOP
I am using authjs so I am just calling session before I fetch in the server. is there a way I can prefetch the auth call and the db call so when you click on it its almost instant?
but anyways if you can get user id from the server side then yeah you can fetch from the server and it's usually better
Yellowstripe scadOP
ok tysm!!
I really appreciate it
Yellowstripe scadOP
@`${ViNoS}` ok I improved the fetch time a lot by simply fetching classes themselves instead of the user with the classes. now I just fetch db.class.findMany and I search for the ones with the user id