Skip to content

Parallelize event details loader queries to improve TTFB#411

Open
zacjones93 wants to merge 1 commit intomainfrom
claude/optimize-score-page-queries-gnI2T
Open

Parallelize event details loader queries to improve TTFB#411
zacjones93 wants to merge 1 commit intomainfrom
claude/optimize-score-page-queries-gnI2T

Conversation

@zacjones93
Copy link
Copy Markdown
Contributor

@zacjones93 zacjones93 commented Apr 19, 2026

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 getAthleteRegisteredDivisionsFn and 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 getWorkoutDivisionDescriptionsFn calls per child event with a single getBatchWorkoutDivisionDescriptionsFn call 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 createServerFn and getUserCompetitionRegistrationsFn that are no longer needed.

Implementation Details

  • The loader now uses parent loader data (divisions and userRegistrations) to avoid redundant queries.
  • Query execution is organized into two phases: Phase 1 (independent queries) and Phase 2 (dependent queries).
  • Video submission results are collected as [trackWorkoutId, result] tuples for cleaner mapping to child events.
  • All division description and video submission logic is now consolidated and easier to follow.

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.

  • Refactors
    • Run independent queries in one Promise.all: event details, judging sheets, event-division mappings, all workouts, venue.
    • Batch division descriptions for parent and child workouts in a single call.
    • Reuse parent userRegistrations; remove the duplicate registrations lookup and unused imports.
    • Fetch video submissions in parallel and map by trackWorkoutId, unifying child vs non-child logic.

Written for commit 96e35c4. Summary will update on new commits.

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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 19, 2026

Warning

Rate limit exceeded

@zacjones93 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 55 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c3c2f8f4-3b49-4f3d-afd5-514cebcfbcb2

📥 Commits

Reviewing files that changed from the base of the PR and between 917e2ec and 96e35c4.

📒 Files selected for processing (1)
  • apps/wodsmith-start/src/routes/compete/$slug/workouts/$eventId.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/optimize-score-page-queries-gnI2T

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants