Commit 67d3d0d1 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Improve tournament lookup behaviour.

parent e9d1f27c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Move Facebook email import timing after account creation.
- Improve consistency of authoritative match creation parameter handling.
- Warn when using deprecated config parameters.
- Improve tournament lookup behaviour.

### Fixed
- Fix log level in Lua runtime log calls which use logger fields.
+10 −2
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ func TournamentsGet(ctx context.Context, logger *zap.Logger, db *sql.DB, tournam
	}
	query := `SELECT id, sort_order, operator, reset_schedule, metadata, create_time, category, description, duration, end_time, max_size, max_num_score, title, size, start_time
FROM leaderboard
WHERE id IN (` + strings.Join(statements, ",") + `) AND duration > 0`
WHERE id IN (` + strings.Join(statements, ",") + `)`

	// Retrieved directly from database to have the latest configuration and 'size' etc field values.
	// Ensures consistency between return data from this call and TournamentList.
@@ -221,10 +221,15 @@ WHERE id IN (` + strings.Join(statements, ",") + `) AND duration > 0`
		return nil, err
	}

	records := make([]*api.Tournament, 0)
	records := make([]*api.Tournament, 0, len(tournamentIDs))
	for rows.Next() {
		tournament, err := parseTournament(rows, now)
		if err != nil {
			if err == ErrTournamentNotFound {
				// This ID mapped to a non-tournament leaderboard, just skip it.
				continue
			}

			_ = rows.Close()
			logger.Error("Error parsing retrieved tournament records", zap.Error(err))
			return nil, err
@@ -695,6 +700,9 @@ func parseTournament(scannable Scannable, now time.Time) (*api.Tournament, error
	if err != nil {
		return nil, err
	}
	if dbDuration <= 0 {
		return nil, ErrTournamentNotFound
	}

	var resetSchedule *cronexpr.Expression
	if dbResetSchedule.Valid {
+4 −0
Original line number Diff line number Diff line
@@ -4698,6 +4698,10 @@ func (n *runtimeJavascriptNakamaModule) tournamentsGetId(r *goja.Runtime) func(g
			tournmentIDs = append(tournmentIDs, idString)
		}

		if len(tournmentIDs) == 0 {
			return r.ToValue(make([]interface{}, 0))
		}

		list, err := TournamentsGet(context.Background(), n.logger, n.db, tournmentIDs)
		if err != nil {
			panic(r.NewGoError(fmt.Errorf("failed to get tournaments: %s", err.Error())))