Parallelize event details loader queries to improve TTFB#411
Parallelize event details loader queries to improve TTFB#411zacjones93 wants to merge 1 commit intomainfrom
Conversation
Previously the /compete/$slug/workouts/$eventId loader ran its DB queries as a sequential waterfall — event → workout division descriptions → venue → all published workouts → video submissions — and issued a redundant user-registrations lookup that the parent loader had already produced. It also fetched each child event's division descriptions in a separate round-trip. This reworks the loader to: - Reuse the parent match's userRegistrations instead of calling getUserCompetitionRegistrationsFn (via the removed inline getAthleteRegisteredDivisionsFn helper) a second time. - Run event details, judging sheets, event-division mappings, all published workouts, and the venue lookup in a single Promise.all. - Use getBatchWorkoutDivisionDescriptionsFn to fetch the event's and all children's division descriptions in one call, and run that in parallel with the video-submission fetches. No behavior changes — the loader's returned shape is unchanged. https://claude.ai/code/session_01TPrvaFiz1tTqRsV8WqWfbj
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 42 minutes and 55 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Refactored the event details page loader to execute independent queries in parallel instead of serially, significantly improving Time To First Byte (TTFB). Previously, queries were chained in a waterfall pattern (event → descriptions → venue → workouts → video submissions), causing unnecessary delays.
Key Changes
Removed custom server function: Deleted
getAthleteRegisteredDivisionsFnand instead derive athlete divisions from parent loader data, eliminating a duplicate registrations query per event page load.Parallelized Phase 1 queries: Moved all independent queries (event details, judging sheets, event-division mappings, all workouts, and venue) into a single
Promise.all()call instead of sequential awaits.Introduced Phase 2 dependent queries: Division descriptions and video submissions now run in parallel after Phase 1 completes, since they depend on results from Phase 1 (e.g., child event IDs, workout IDs).
Batched division descriptions: Replaced individual
getWorkoutDivisionDescriptionsFncalls per child event with a singlegetBatchWorkoutDivisionDescriptionsFncall that fetches descriptions for the parent event and all children in one query.Simplified video submission logic: Consolidated video submission fetching into a single
Promise.all()that maps results back to their corresponding track workout IDs, eliminating separate branches for child vs. non-child events.Removed unused imports: Cleaned up imports for
createServerFnandgetUserCompetitionRegistrationsFnthat are no longer needed.Implementation Details
divisionsanduserRegistrations) to avoid redundant queries.[trackWorkoutId, result]tuples for cleaner mapping to child events.https://claude.ai/code/session_01TPrvaFiz1tTqRsV8WqWfbj
Summary by cubic
Parallelized the event details loader and batched division description queries to cut TTFB on the score page. Reused parent loader data and simplified video submission fetching; no behavior changes.
userRegistrations; remove the duplicate registrations lookup and unused imports.trackWorkoutId, unifying child vs non-child logic.Written for commit 96e35c4. Summary will update on new commits.