fix: delete goals once per match instead of once per team in syncGoals()
syncGoals() was calling DELETE FROM goals WHERE match_id=X at the top, so processing goals2 (away team) wiped out goals1 (home team) that were just inserted. Every match with goals from both sides lost all home-team goals — Ronaldo's hat-trick vs Spain, Kane's vs Panama, and many others. Fix: move DELETE above the goals1/goals2 loop, executed once per match. Result: 2018 goal count corrected from 107 → 169; hat tricks from 8 → 18. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+3
-1
@@ -226,7 +226,6 @@ async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function syncGoals(matchId: number, teamId: number, rawGoals: RawGoal[], isOwnGoalTeamId: number) {
|
async function syncGoals(matchId: number, teamId: number, rawGoals: RawGoal[], isOwnGoalTeamId: number) {
|
||||||
await db.execute(sql`DELETE FROM goals WHERE match_id = ${matchId}`)
|
|
||||||
for (const g of rawGoals) {
|
for (const g of rawGoals) {
|
||||||
if (!g.name) continue
|
if (!g.name) continue
|
||||||
const minute = g.minute != null ? parseInt(String(g.minute)) : null
|
const minute = g.minute != null ? parseInt(String(g.minute)) : null
|
||||||
@@ -294,8 +293,11 @@ async function run() {
|
|||||||
const score = parseScore(m.score)
|
const score = parseScore(m.score)
|
||||||
const group = m.group ?? null
|
const group = m.group ?? null
|
||||||
const matchId = await upsertMatch(year, m.round ?? 'Unknown', group, m.date ?? null, m.time ?? null, t1Id, t2Id, score, false)
|
const matchId = await upsertMatch(year, m.round ?? 'Unknown', group, m.date ?? null, m.time ?? null, t1Id, t2Id, score, false)
|
||||||
|
if (m.goals1?.length || m.goals2?.length) {
|
||||||
|
await db.execute(sql`DELETE FROM goals WHERE match_id = ${matchId}`)
|
||||||
if (m.goals1?.length) await syncGoals(matchId, t1Id, m.goals1, t2Id)
|
if (m.goals1?.length) await syncGoals(matchId, t1Id, m.goals1, t2Id)
|
||||||
if (m.goals2?.length) await syncGoals(matchId, t2Id, m.goals2, t1Id)
|
if (m.goals2?.length) await syncGoals(matchId, t2Id, m.goals2, t1Id)
|
||||||
|
}
|
||||||
matchCount++
|
matchCount++
|
||||||
goalCount += (m.goals1?.length ?? 0) + (m.goals2?.length ?? 0)
|
goalCount += (m.goals1?.length ?? 0) + (m.goals2?.length ?? 0)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user