From ac7c3188990bae0c221972a5a9d181952d472daa Mon Sep 17 00:00:00 2001 From: deploy Date: Fri, 19 Jun 2026 10:48:44 +0000 Subject: [PATCH] fix(player): pick most-recent squadron_members row when uid has duplicates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A player who changed squadrons could end up with two rows in squadron_members (old + new clan). Without ORDER BY, LIMIT 1 returned whichever row the primary-key B-tree (clan_id, uid) put first — i.e. the lowest clan_id, which was the stale entry. This caused the player page to show the old squadron while the homepage search (which only reads player_games_hist) showed the correct one. Fix: add ORDER BY updated_at DESC to both the API roster lookup in server.js and the web fallback lookup in web/server.js, so the most recently synced membership always wins. Co-Authored-By: Claude Sonnet 4.6 --- server.js | 2 +- web/server.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index fa01d14..8526e7a 100644 --- a/server.js +++ b/server.js @@ -1983,7 +1983,7 @@ app.get('/api/player/:uid', (req, res) => { const sdb = new sqlite3.Database(squadronsDbPath, sqlite3.OPEN_READONLY, (err) => { if (err) return resolve(null); sdb.get( - 'SELECT clan_id FROM squadron_members WHERE uid = ? LIMIT 1', + 'SELECT clan_id FROM squadron_members WHERE uid = ? ORDER BY updated_at DESC LIMIT 1', [uid], (qerr, row) => { sdb.close(); diff --git a/web/server.js b/web/server.js index 7fd8fb4..1426c56 100644 --- a/web/server.js +++ b/web/server.js @@ -74,6 +74,7 @@ function getRosterMemberByUid(uid) { FROM squadron_members sm LEFT JOIN squadrons_data sd ON sm.clan_id = sd.clan_id WHERE sm.uid = ? + ORDER BY sm.updated_at DESC LIMIT 1 `, [uid],