Skip to content

Commit

Permalink
Fix leaderboard rank cache initialization upon startup (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
syhpoon committed Apr 18, 2024
1 parent b320ca5 commit b229b1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
## [Unreleased]
### Fixed
- Ensure Apple receipts with duplicate transaction identifiers are processed cleanly.
- Fix leaderboard rank cache initialization upon startup.

## [3.21.1] - 2024-03-22
### Added
Expand Down
7 changes: 5 additions & 2 deletions server/leaderboard_rank_cache.go
Expand Up @@ -458,6 +458,7 @@ func leaderboardCacheInitWorker(
for leaderboard := range ch {
var score int64
var subscore int64
var generation int32
var ownerIDStr string

mu.Lock()
Expand Down Expand Up @@ -498,7 +499,7 @@ func leaderboardCacheInitWorker(
for {
ranks := make(map[uuid.UUID]skiplist.Interface, batchSize)

query := "SELECT owner_id, score, subscore FROM leaderboard_record WHERE leaderboard_id = $1 AND expiry_time = $2"
query := "SELECT owner_id, score, subscore, num_score FROM leaderboard_record WHERE leaderboard_id = $1 AND expiry_time = $2"
params := []interface{}{leaderboard.Id, expiryTime}
if ownerIDStr != "" {
query += " AND (leaderboard_id, expiry_time, score, subscore, owner_id) > ($1, $2, $3, $4, $5)"
Expand All @@ -521,7 +522,7 @@ func leaderboardCacheInitWorker(

// Read score information.
for rows.Next() {
if err = rows.Scan(&ownerIDStr, &score, &subscore); err != nil {
if err = rows.Scan(&ownerIDStr, &score, &subscore, &generation); err != nil {
startupLogger.Error("Failed to scan leaderboard rank data", zap.String("leaderboard_id", leaderboard.Id), zap.Error(err))
break
}
Expand All @@ -535,6 +536,8 @@ func leaderboardCacheInitWorker(
// Prepare new rank data for this leaderboard entry.
rankData := newRank(leaderboard.SortOrder, score, subscore, ownerID)
ranks[ownerID] = rankData

rankCache.owners[ownerID] = cachedRecord{generation: generation, record: rankData}
}
_ = rows.Close()

Expand Down

0 comments on commit b229b1d

Please sign in to comment.