Unverified Commit 805e63e7 authored by Fernando Takagi's avatar Fernando Takagi Committed by GitHub
Browse files

Tournament add attempt operation expiry improvements. (#898)

parent b4eb1697
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ local du = require("debug_utils")
--]]

local function tournament_end_callback(_context, tournament, sessionEnd, expiry)
  local records, owner_records, nc, pc = nk.leaderboard_records_list(tournament.id, nil, 1)
  local records, owner_records, nc, pc = nk.leaderboard_records_list(tournament.id, nil, 1, "", expiry)
  if #records >= 1 then
    local user_id = records[1].owner_id
    local metadata = { won = tournament.id }
+7 −6
Original line number Diff line number Diff line
@@ -104,12 +104,13 @@ func TournamentAddAttempt(ctx context.Context, logger *zap.Logger, db *sql.DB, c
		return runtime.ErrTournamentNotFound
	}

	expiryTime := int64(0)
	if leaderboard.ResetSchedule != nil {
		expiryTime = leaderboard.ResetSchedule.Next(time.Now().UTC()).UTC().Unix()
		if leaderboard.EndTime > 0 && expiryTime > leaderboard.EndTime {
			expiryTime = leaderboard.EndTime
		}
	nowTime := time.Now().UTC()
	nowUnix := nowTime.Unix()

	_, endActive, expiryTime := calculateTournamentDeadlines(leaderboard.StartTime, leaderboard.EndTime, int64(leaderboard.Duration), leaderboard.ResetSchedule, nowTime)
	if endActive <= nowUnix {
		logger.Info("Cannot add attempt outside of tournament duration.")
		return runtime.ErrTournamentOutsideDuration
	}

	query := `UPDATE leaderboard_record SET max_num_score = (max_num_score + $1) WHERE leaderboard_id = $2 AND owner_id = $3 AND expiry_time = $4`