Skip to content

Commit 5666361

Browse files
authored
Add leaderboard record list around owner cursors (#877)
Minor improvement to leaderbord cache creation Update nakama-common dependencies
1 parent 2192e99 commit 5666361

File tree

16 files changed

+403
-314
lines changed

16 files changed

+403
-314
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
1111
- Improve runtime handling of non-persisted purchases and subscriptions.
1212
- Improve validation of count multiple matchmaker parameter.
1313
- Stricter validation of devconsole user email inputs.
14+
- Added next and previous cursor to results of the Leaderboard/TournamentRecordsAroundOwner API and Leaderboard/TournamentRecordsHaystack runtime functions.
1415

1516
## [3.12.0] - 2022-05-22
1617
### Added

data/modules/index.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/gorilla/mux v1.8.0
1414
github.com/gorilla/websocket v1.4.2
1515
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0
16-
github.com/heroiclabs/nakama-common v1.23.1-0.20220529114835-7f3eb1c918ff
16+
github.com/heroiclabs/nakama-common v1.23.1-0.20220705161131-2c524612cd4a
1717
github.com/jackc/pgconn v1.10.0
1818
github.com/jackc/pgerrcode v0.0.0-20201024163028-a0d42d470451
1919
github.com/jackc/pgtype v1.8.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
292292
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
293293
github.com/heroiclabs/nakama-common v1.23.1-0.20220529114835-7f3eb1c918ff h1:ulAC9PUbx+9hSwDBg+nHLNFa5uOZv0/lO93eecMRz0Q=
294294
github.com/heroiclabs/nakama-common v1.23.1-0.20220529114835-7f3eb1c918ff/go.mod h1:WF4YG46afwY3ibzsXnkt3zvhQ3tBY03IYeU7xSLr8HE=
295+
github.com/heroiclabs/nakama-common v1.23.1-0.20220705161131-2c524612cd4a h1:W8Od/R4nkjX14vnDWRMkc/9BFKEbFqwWQtvFl8H4tkY=
296+
github.com/heroiclabs/nakama-common v1.23.1-0.20220705161131-2c524612cd4a/go.mod h1:WF4YG46afwY3ibzsXnkt3zvhQ3tBY03IYeU7xSLr8HE=
295297
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
296298
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
297299
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=

server/api_leaderboard.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,22 @@ func (s *ApiServer) ListLeaderboardRecordsAroundOwner(ctx context.Context, in *a
262262
overrideExpiry = in.Expiry.Value
263263
}
264264

265-
records, err := LeaderboardRecordsHaystack(ctx, s.logger, s.db, s.leaderboardCache, s.leaderboardRankCache, in.GetLeaderboardId(), ownerID, limit, overrideExpiry)
265+
records, err := LeaderboardRecordsHaystack(ctx, s.logger, s.db, s.leaderboardCache, s.leaderboardRankCache, in.GetLeaderboardId(), in.Cursor, ownerID, limit, overrideExpiry)
266266
if err == ErrLeaderboardNotFound {
267267
return nil, status.Error(codes.NotFound, "Leaderboard not found.")
268268
} else if err != nil {
269269
return nil, status.Error(codes.Internal, "Error querying records from leaderboard.")
270270
}
271271

272-
recordList := &api.LeaderboardRecordList{Records: records}
273-
274272
// After hook.
275273
if fn := s.runtime.AfterListLeaderboardRecordsAroundOwner(); fn != nil {
276274
afterFn := func(clientIP, clientPort string) error {
277-
return fn(ctx, s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxVarsKey{}).(map[string]string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, recordList, in)
275+
return fn(ctx, s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxVarsKey{}).(map[string]string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, records, in)
278276
}
279277

280278
// Execute the after function lambda wrapped in a trace for stats measurement.
281279
traceApiAfter(ctx, s.logger, s.metrics, ctx.Value(ctxFullMethodKey{}).(string), afterFn)
282280
}
283281

284-
return recordList, nil
282+
return records, nil
285283
}

server/api_tournament.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,24 +379,22 @@ func (s *ApiServer) ListTournamentRecordsAroundOwner(ctx context.Context, in *ap
379379
overrideExpiry = in.Expiry.Value
380380
}
381381

382-
records, err := TournamentRecordsHaystack(ctx, s.logger, s.db, s.leaderboardCache, s.leaderboardRankCache, in.GetTournamentId(), ownerID, limit, overrideExpiry)
382+
records, err := TournamentRecordsHaystack(ctx, s.logger, s.db, s.leaderboardCache, s.leaderboardRankCache, in.GetTournamentId(), in.Cursor, ownerID, limit, overrideExpiry)
383383
if err == ErrLeaderboardNotFound {
384384
return nil, status.Error(codes.NotFound, "Tournament not found.")
385385
} else if err != nil {
386386
return nil, status.Error(codes.Internal, "Error querying records from leaderboard.")
387387
}
388388

389-
list := &api.TournamentRecordList{Records: records}
390-
391389
// After hook.
392390
if fn := s.runtime.AfterListTournamentRecordsAroundOwner(); fn != nil {
393391
afterFn := func(clientIP, clientPort string) error {
394-
return fn(ctx, s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxVarsKey{}).(map[string]string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, list, in)
392+
return fn(ctx, s.logger, ctx.Value(ctxUserIDKey{}).(uuid.UUID).String(), ctx.Value(ctxUsernameKey{}).(string), ctx.Value(ctxVarsKey{}).(map[string]string), ctx.Value(ctxExpiryKey{}).(int64), clientIP, clientPort, records, in)
395393
}
396394

397395
// Execute the after function lambda wrapped in a trace for stats measurement.
398396
traceApiAfter(ctx, s.logger, s.metrics, ctx.Value(ctxFullMethodKey{}).(string), afterFn)
399397
}
400398

401-
return list, nil
399+
return records, nil
402400
}

0 commit comments

Comments
 (0)