Skip to content

Conversation

@ianpaschal
Copy link
Owner

@ianpaschal ianpaschal commented Dec 12, 2025

Migration for #274


Summary by CodeRabbit

  • Bug Fixes

    • Improved tournament ranking calculation efficiency and accuracy by optimizing result retrieval and consolidating data aggregation logic.
  • Chores

    • Internal database migration to ensure tournament ranking data consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
combat-command Ready Ready Preview Comment Dec 12, 2025 1:04pm

@coderabbitai
Copy link

coderabbitai bot commented Dec 12, 2025

Walkthrough

A tournament result retrieval optimization in the mutation layer combined with a new migration to fix ranking factors for tournaments. The mutation consolidates duplicate queries into a single top-level fetch, while the migration introduces data aggregation and patching logic for archived tournament rankings.

Changes

Cohort / File(s) Summary
Tournament Result Refactoring
convex/_model/tournamentResults/mutations/refreshTournamentResult.ts
Moved existingResult query to function top using by_tournament_round index; removed duplicate fetch; simplified result construction via inline object spread in map expression.
Migration Addition
convex/migrations.ts
Added fixRankingFactors migration targeting tournaments table. For archived tournaments, iterates rounds to fetch tournamentResult, retrieve tournament and competitors, aggregate ranking data, and patch results with updated registrations and competitors. Handles specific tournament id with direct patch; others use refreshTournamentResult. Introduced imports: GameSystem, ConvexError, getErrorMessage, aggregateTournamentData, applyScoreAdjustments, getTournamentShallow.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Migration logic verification: The fixRankingFactors migration contains multiple conditional branches, data aggregation steps, and rank-preserving transformations that require careful trace-through to ensure correctness, especially the merging of rankingFactors and average_opponent_wins preservation logic.
  • Refactoring correctness: Verify that moving the existingResult query to the top and removing duplicate fetches maintains the intended behavior and doesn't introduce stale data issues.
  • Index usage: Confirm the by_tournament_round index exists and query filters are optimal.
  • Data integrity during migration: Review the special-case handling for the specific tournament id and the conditional refresh logic for other tournaments.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 4f9e965 and 8b7f727.

📒 Files selected for processing (2)
  • convex/_model/tournamentResults/mutations/refreshTournamentResult.ts (2 hunks)
  • convex/migrations.ts (2 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

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