Skip to content

Optimize /update_points DB scoring path#47

Closed
mateu wants to merge 1 commit into
masterfrom
koan/optimize-update-points-db-path
Closed

Optimize /update_points DB scoring path#47
mateu wants to merge 1 commit into
masterfrom
koan/optimize-update-points-db-path

Conversation

@mateu
Copy link
Copy Markdown
Owner

@mateu mateu commented Apr 5, 2026

What: Optimize the database-heavy update_points path (portable DBIC branch) by replacing object-heavy loops with set-based SQL and hashref lookups.

Why: /update_points is an admin hot path, and the previous portable implementation inflated many DBIx::Class row objects and performed per-row updates that scale poorly with player/pick volume.

How: Use hashref inflators for topology/winner lookups, run prepared SQL updates for game/team mutations, and rebuild region_score in one INSERT ... SELECT (cross-joining players/regions with aggregated winning picks), then recalculate player totals with one correlated UPDATE.

Testing: Ran script/test-env.sh prove -lv t/model_update_points.t, script/test-env.sh prove -lr t, and syntax checks with repo-local env includes.


Quality Report

Changes: 2 files changed, 143 insertions(+), 91 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

@mateu mateu marked this pull request as ready for review April 5, 2026 19:49
@mateu mateu requested a review from Copilot April 5, 2026 19:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Optimizes the non-MySQL (“portable”) /update_points scoring implementation in Bracket::Model::DBIC to reduce DBIx::Class row-object inflation and replace per-row updates with more set-based SQL.

Changes:

  • Switch portable-path lookup queries to HashRefInflator and hash-based lookups for game rounds, team seeds, and topology edges.
  • Replace object-heavy update loops with prepared SQL updates for game (winner/lower_seed) and team (round_out).
  • Rebuild region_score via a single INSERT ... SELECT (player×region cross join + aggregated winning picks), then recompute player.points with one correlated UPDATE; extend the test to assert zeroed rows for players with no winning picks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/Bracket/Model/DBIC.pm Reworks the portable scoring path to use hashref inflators + prepared statements + set-based rebuilds for region_score and player.points.
t/model_update_points.t Adds coverage ensuring players with no winning picks still receive 4 zeroed region_score rows and a 0 total.

@mateu mateu closed this Apr 7, 2026
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