Leaderboard prev cursor

Hello,

I am currently dealing with the leaderboard and I noticed something about the prev cursor. While there is no problem with the record list that I first call with the prev cursor, when I call the 2nd call, the sorting is broken, what could be the reason?

here’s my code

private async void GetLeaderboard(string cursor)
        {
            try
            {
                var recordList = await Client.ListLeaderboardRecordsAsync(Session, "test", null, null, 5, cursor);
                List<IApiLeaderboardRecord> apiLeaderboardRecords = recordList.Records.ToList();
                apiLeaderboardRecords = apiLeaderboardRecords
                    .OrderByDescending(record => int.Parse(record.Score)) 
                    .ToList();

                var sortedRanks = apiLeaderboardRecords
                    .Select(record => int.Parse(record.Rank))
                    .OrderBy(rank => rank) 
                    .ToList();

                _nextCursor = recordList.NextCursor;
                _prevCursor = recordList.PrevCursor;
                
                string logMessage = "Fetched Records:\n";
                for (int i = 0; i < apiLeaderboardRecords.Count; i++)
                {
                    var record = apiLeaderboardRecords[i];
                    int newRank = sortedRanks[i];
                    logMessage += $"Score: {record.Score}, Rank: {newRank}\n";
                }
                Debug.Log(logMessage);
            }
            catch (System.Exception ex)
            {
                Debug.LogError($"Error fetching leaderboard: {ex.Message}");
            }
        }

lederboard outputs that I called twice using the next cursor and twice using the prev cursor:

--- log at the start of the game ---
Fetched Records:
Score: 266, Rank: 1
Score: 226, Rank: 2
Score: 206, Rank: 3
Score: 197, Rank: 4
Score: 179, Rank: 5

--- the first log I used the next cursor ---
Fetched Records:
Score: 170, Rank: 6
Score: 166, Rank: 7
Score: 158, Rank: 8
Score: 153, Rank: 9
Score: 151, Rank: 10

--- the second log I use the next cursor ---
Fetched Records:
Score: 150, Rank: 11
Score: 150, Rank: 12
Score: 149, Rank: 13
Score: 149, Rank: 14
Score: 147, Rank: 15

---  the first log I used the prev cursor ---
Fetched Records:
Score: 170, Rank: 6
Score: 166, Rank: 7
Score: 158, Rank: 8
Score: 153, Rank: 9
Score: 151, Rank: 10

--- the second log I use the prev cursor ---
Fetched Records:
Score: 266, Rank: 5
Score: 226, Rank: 6
Score: 206, Rank: 7
Score: 197, Rank: 8
Score: 179, Rank: 9

Am I missing something? Maybe you can see what I can’t see, thank you in advance for your help.

Hello @omerfarukkvk,

Are you running the latest Nakama version?

Hello @sesposito,

Server version: 3.22.0+4a4c53d7

Nakama Unity version: 3.13.0

I couldn’t reproduce on 3.25.0 with a descending leaderboard with 81 records, I used the next_cursor to fetch 3 pages of records with limit 5 and then from there used the prev_cursor to get the previous pages (I used the REST API directly).

You shouldn’t need to order the records. If you keep encountering the issue, please provide a reproducible example to setup the leaderboard and listing to reproduce.

Best.