Commit 7c09e3ba authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Correctly calculate 'can enter' field for newly created tournaments.

parent c6a74626
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Update username on leaderboard and tournament records when processing a score update.
- Automatically stop empty authoritative matches after a configurable amount of time.

### Fixed
- Correctly calculate 'can enter' field for newly created tournaments.

## [2.9.1] - 2020-01-14
### Changed
- Build with Go 1.13.6 release.
+1 −1
Original line number Diff line number Diff line
@@ -611,7 +611,7 @@ func parseTournament(scannable Scannable, now time.Time) (*api.Tournament, error
		canEnter = false
	}

	if canEnter && dbSize == dbMaxSize {
	if canEnter && dbSize >= dbMaxSize {
		canEnter = false
	}

+8 −5
Original line number Diff line number Diff line
@@ -477,14 +477,17 @@ func (l *LocalLeaderboardCache) CreateTournament(ctx context.Context, id string,
		values += "$" + v
	}

	query := "INSERT INTO leaderboard (" + columns + ") VALUES (" + values + ") RETURNING create_time, start_time, end_time"
	query := "INSERT INTO leaderboard (" + columns + ") VALUES (" + values + ") RETURNING metadata, max_size, max_num_score, create_time, start_time, end_time"

	l.logger.Debug("Create tournament query", zap.String("query", query))

	var dbMetadata string
	var dbMaxSize int
	var dbMaxNumScore int
	var createTime pgtype.Timestamptz
	var dbStartTime pgtype.Timestamptz
	var dbEndTime pgtype.Timestamptz
	err = l.db.QueryRowContext(ctx, query, params...).Scan(&createTime, &dbStartTime, &dbEndTime)
	err = l.db.QueryRowContext(ctx, query, params...).Scan(&dbMetadata, &dbMaxSize, &dbMaxNumScore, &createTime, &dbStartTime, &dbEndTime)
	if err != nil {
		l.logger.Error("Error creating tournament", zap.Error(err))
		return nil, err
@@ -497,15 +500,15 @@ func (l *LocalLeaderboardCache) CreateTournament(ctx context.Context, id string,
		Operator:         operator,
		ResetScheduleStr: resetSchedule,
		ResetSchedule:    resetCron,
		Metadata:         metadata,
		Metadata:         dbMetadata,
		CreateTime:       createTime.Time.Unix(),
		Category:         category,
		Description:      description,
		Duration:         duration,
		EndTime:          0,
		JoinRequired:     joinRequired,
		MaxSize:          maxSize,
		MaxNumScore:      maxNumScore,
		MaxSize:          dbMaxSize,
		MaxNumScore:      dbMaxNumScore,
		Title:            title,
		StartTime:        dbStartTime.Time.Unix(),
	}