Unverified Commit f0bd8b8e authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Stricter ordering of returned leaderboard owner records. (#1039)

parent 4bccf1d6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -20,13 +20,14 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr

### Fixed
- Correct cursor usage in group listings using only open/closed group state filter.
- Remap original Google IDs to "next generation player IDs".
- Fix issue delivering persistent SendAll notifications to large numbers of users.
- Remove incorrect category start and category end parameters from runtime leaderboard list functions.
- Graceful handling of idempotent tournament creation operations.
- Correct sorting of batched storage write and delete operations.
- Fix indexing of channel message list responses in Lua runtime.
- Better handling of parameters submitted from the devconsole UI.
- Remap original Google IDs to "next generation player IDs"
- Return ordered owner records in leaderboard/tournament records listings.

## [3.16.0] - 2023-04-18
### Added
+27 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import (
	"encoding/base64"
	"encoding/gob"
	"errors"
	"sort"
	"strconv"
	"strings"
	"time"
@@ -343,6 +344,32 @@ func LeaderboardRecordsList(ctx context.Context, logger *zap.Logger, db *sql.DB,
		_ = rows.Close()
	}

	// Sort owner records according to leaderboard ordering
	var sortFn func(i, j int) bool
	if leaderboard.SortOrder == LeaderboardSortOrderAscending {
		sortFn = func(i, j int) bool {
			if ownerRecords[i].Score == ownerRecords[j].Score {
				if ownerRecords[i].Subscore == ownerRecords[j].Subscore {
					return ownerRecords[i].OwnerId < ownerRecords[j].OwnerId
				}
				return ownerRecords[i].Subscore < ownerRecords[j].Subscore
			}
			return ownerRecords[i].Score < ownerRecords[j].Score
		}
	} else {
		sortFn = func(i, j int) bool {
			if ownerRecords[i].Score == ownerRecords[j].Score {
				if ownerRecords[i].Subscore == ownerRecords[j].Subscore {
					return ownerRecords[i].OwnerId > ownerRecords[j].OwnerId
				}
				return ownerRecords[i].Subscore > ownerRecords[j].Subscore
			}
			return ownerRecords[i].Score > ownerRecords[j].Score
		}
	}

	sort.Slice(ownerRecords, sortFn)

	// Bulk fill in the ranks of any owner records requested.
	rankCache.Fill(leaderboardId, leaderboard.SortOrder, expiryTime, ownerRecords)