Refactor and optimize: deduplicate, batch queries, fix bugs

- Remove unused DATABASE_PATH import from games.py
- Extract _new_game_context(db) helper to deduplicate GET/POST error path
- Extract _parse_hole_form() helper to deduplicate hole validation in create/edit course
- Batch N+1 player handicap and tee queries in create_game into two IN() queries
- Fix hole count import bug: use max() across all tees instead of first match
- Fix migration exception handling: re-raise unless "duplicate column name"
- Cache calcSkins() result in _skinsCache; invalidate on score/skip changes
- Collapse two identical Next buttons into one in new_game.html
- Fix stale skinDoubleBackNine checkbox: reset on mode change, use x-model

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Rolf
2026-03-23 22:52:45 +01:00
parent d81d6a2d3c
commit 0be6e908e6
5 changed files with 101 additions and 118 deletions
+7 -1
View File
@@ -307,6 +307,7 @@ function gameApp() {
touchStartX: 0,
dragSrc: null,
dragOver: null,
_skinsCache: null,
init() {
this.players = PLAYERS_DATA;
@@ -339,6 +340,7 @@ function gameApp() {
this.scores[h][uid] = s;
}
this.totals = msg.totals;
this._skinsCache = null;
}
};
this.ws.onclose = () => setTimeout(() => this.connectWs(), 2000);
@@ -358,6 +360,7 @@ function gameApp() {
const cur = this.scores[hole][uid].strokes;
this.scores[hole][uid].strokes = cur ? Math.max(1, cur + delta) : (HOLE_PARS[hole] || 4);
this.dirty.add(hole);
this._skinsCache = null;
},
setBingo(hole, uid) {
@@ -441,6 +444,7 @@ function gameApp() {
}
// Alpine reactivity workaround for Set
this.skipped = new Set(this.skipped);
this._skinsCache = null;
},
isSkipped(hole) {
@@ -503,6 +507,7 @@ function gameApp() {
touchDragEnd() { this.dropPlayer(this.dragOver ?? this.dragSrc); },
calcSkins() {
if (this._skinsCache) return this._skinsCache;
const skins = {};
const money = {};
PLAYERS_DATA.forEach(p => { skins[p.id] = 0; money[p.id] = 0; });
@@ -535,7 +540,8 @@ function gameApp() {
if (!SKINS_CARRYOVER) { pot = 0; moneyPot = 0; }
}
}
return { skins, money, holes, unclaimed: pot, unclaimedMoney: moneyPot };
this._skinsCache = { skins, money, holes, unclaimed: pot, unclaimedMoney: moneyPot };
return this._skinsCache;
},
isSkinWinner(hole, uid) {