Unverified Commit e6bb8a46 authored by Luke's avatar Luke Committed by GitHub
Browse files

fix off-by-one error in indexing leaderboard records around owner (#605)

* calculate start and end of leaderboard record slice from owner pivot

* use more consistent terminology in slice comments

* simplify leaderboard around owner algorithm
parent 4ffd40a6
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -628,12 +628,17 @@ func getLeaderboardRecordsHaystack(ctx context.Context, logger *zap.Logger, db *
	records := append(firstRecords, ownerRecord)
	records = append(records, secondRecords...)

	start := len(records) - int(limit)
	if start < 0 {
	numRecords := len(records)
	start := numRecords - int(limit)
	if len(firstRecords) < limit/2 {
		start = 0
	}
	end := start + int(limit)
	if end > numRecords {
		end = numRecords
	}

	records = records[start:]
	records = records[start:end]
	rankCache.Fill(leaderboardId, expiryTime.Unix(), records)

	return records, nil