SSR / Server Side Fetching 4+ seconds on production
Unanswered
Yellowstripe scad posted this in #help-forum
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 scad 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.
5s is a lot
try to first identify what exactly is taking time
check the database call first
you can use
for that
try to first identify what exactly is taking time
check the database call first
you can use
const t0 = performance.now();
// some code
const t1 = performance.now();
console.log(t1 - t0, 'milliseconds');for that
@`${ViNoS}` 5s is a lot
try to first identify what exactly is taking time
check the database call first
you can use
js
const t0 = performance.now();
// some code
const t1 = performance.now();
console.log(t1 - t0, 'milliseconds');
for that
Yellowstripe scadOP
so would I put t0 above the db call and t1 below it?
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 scad had to zoom out a bit but I hope this is what you mean
i see
that ain't much data
that ain't much data
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 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
@`${ViNoS}` 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
Yellowstripe scadOP
I was probably exaggerating a bit
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
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)
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?
@Yellowstripe scad 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?
never took a look at it
i am sorry, i don't have time rn to check how this authjs works
i am sorry, i don't have time rn to check how this authjs works
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
@Yellowstripe scad <@347392731431174166> 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
great
and yeah, this is better than making all these joins
good luck
and yeah, this is better than making all these joins
good luck