mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 18:03:43 +00:00
fix(multiplayer): finalize empty ranked seasons
This commit is contained in:
@@ -24,6 +24,12 @@ WHERE season_id = $1 AND rolled_over_at IS NULL
|
||||
LEFT JOIN ranked_season_rollovers rr ON rr.season_id = $1 AND rr.player_id = r.player_id
|
||||
WHERE rr.player_id IS NULL)`
|
||||
|
||||
const MarkEmptySeasonsSQL = `UPDATE seasons s SET rolled_over_at = $1
|
||||
WHERE s.playlist = 'ranked' AND s.ends_at <= $1 AND s.rolled_over_at IS NULL
|
||||
AND NOT EXISTS (SELECT 1 FROM ratings r
|
||||
LEFT JOIN ranked_season_rollovers rr ON rr.season_id = s.season_id AND rr.player_id = r.player_id
|
||||
WHERE rr.player_id IS NULL)`
|
||||
|
||||
type dueSeasonRollover struct {
|
||||
seasonID string
|
||||
playerID string
|
||||
@@ -36,6 +42,12 @@ func RolloverDueSeasons(ctx context.Context, db *sql.DB, now time.Time, limit in
|
||||
if db == nil || now.IsZero() || limit < 1 || limit > 1000 {
|
||||
return 0, fmt.Errorf("invalid season maintenance arguments")
|
||||
}
|
||||
// A season with no ranked profiles has no player row for DueSeasonRolloversSQL
|
||||
// to return. Mark it here so maintenance remains idempotent instead of
|
||||
// reconsidering the same empty season on every pass.
|
||||
if _, err := db.ExecContext(ctx, MarkEmptySeasonsSQL, now); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
rows, err := db.QueryContext(ctx, DueSeasonRolloversSQL, now, limit)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Reference in New Issue
Block a user