Skip to content

fix: parallelize analytics queries with Promise.all to prevent 504 timeouts#243

Open
sachin-mahato25 wants to merge 1 commit into
knoxiboy:mainfrom
sachin-mahato25:fix/classroom-dashboard-n-plus-one
Open

fix: parallelize analytics queries with Promise.all to prevent 504 timeouts#243
sachin-mahato25 wants to merge 1 commit into
knoxiboy:mainfrom
sachin-mahato25:fix/classroom-dashboard-n-plus-one

Conversation

@sachin-mahato25
Copy link
Copy Markdown

Closes #223

Problem

The analytics endpoint ran 7 database queries sequentially, causing
the Vercel serverless function to exceed the 10-second timeout limit
for classrooms with 50+ users, resulting in 504 Gateway Timeout errors.

Fix

Wrapped all 7 independent queries in Promise.all() so they execute
in parallel. Response time is now determined by the slowest single
query instead of the sum of all queries.

Changes

  • app/api/analytics/route.ts — parallelized all analytics queries

@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

@sachin-mahato25 is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@sachin-mahato25
Copy link
Copy Markdown
Author

Hey @knoxiboy!
I've investigated the issue and found that the GET /api/analytics
endpoint was running 7 database queries sequentially, causing the total response
time to exceed Vercel's 10-second timeout limit for classrooms with 50+ users.

Fixed this by wrapping all 7 independent queries in Promise.all() so they now
execute in parallel, reducing response time from the sum of all queries to just
the slowest single query. No changes to API response shape or existing functionality.

PR has been submitted for your review. Looking forward to your feedback! 🙏

@knoxiboy knoxiboy added gssoc'26 GSSoC program issue type:bug Bug fix level:intermediate Intermediate level task labels May 24, 2026
knoxiboy

This comment was marked as outdated.

knoxiboy

This comment was marked as outdated.

Copy link
Copy Markdown
Owner

@knoxiboy knoxiboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical Review

Hi @sachin-mahato25! Thank you for your contribution to DoubtDesk.

The code changes look good. Before we can complete the technical review, approve, and merge this pull request, we have one final requirement for all contributors: Please star the DoubtDesk repository.

Once you have starred the repository, please drop a comment here saying "done" (or we will automatically detect it) and we will proceed with approving and merging your PR. Thank you.

@knoxiboy knoxiboy self-requested a review May 24, 2026 12:27
@knoxiboy knoxiboy added gssoc and removed gssoc labels May 24, 2026
@sachin-mahato25
Copy link
Copy Markdown
Author

@knoxiboy Done! ⭐ I have starred the DoubtDesk repository. Thank you for reviewing my contribution.

Copy link
Copy Markdown
Owner

@knoxiboy knoxiboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: Thank you for starring the repository! The PR is approved.\n\nNote: This PR currently has merge conflicts with the main branch. Please resolve the merge conflicts so we can complete the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc'26 GSSoC program issue level:intermediate Intermediate level task type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Excessive database query latency on classroom dashboard causing 504 Gateway Timeouts

2 participants