Back to articles
My dashboard was taking 47 seconds to load. Turns out i was making 600 database queries without knowing it

My dashboard was taking 47 seconds to load. Turns out i was making 600 database queries without knowing it

via Dev.to Webdevhelpdevtools

i was building a simple dashboard. nothing fancy. just fetch some user data and display it. opened it to test something and just stared at my screen for almost a minute. 47 seconds to load. for 200 users. first i did what every developer does. checked the network tab. refreshed 3 times. blamed my wifi. still 47 seconds. so i stopped guessing and used an AI prompt to find the problem. here's the prompt i used: "Act as a performance engineer. This code is running slower than expected. The app loads a dashboard that fetches user data. With 100 users it loads in 200ms. With 10,000 users it takes 45 seconds and sometimes crashes. Identify the bottleneck, explain why it's slow, and rewrite an optimized version with comments on what changed." the response was not what i expected. i was making 3 separate database calls inside a loop. one for the profile, one for orders, one for last login. per user. every single time someone opened the dashboard. sounds fine when you write it. its not fine whe

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
5 views

Related Articles