Table of Contents

Class LeaderboardService

Namespace
FishMMO.Database.Npgsql.Services
Assembly
FishMMO-DB.dll

Read-only leaderboards. See ILeaderboardService.

public sealed class LeaderboardService : BaseService<CharacterEntity>, ILeaderboardService
Inheritance
LeaderboardService
Implements
Inherited Members

Remarks

Every board is the same three statements over a different FROM clause: the rows of a page, the count of the whole board, and one character's standing. The FROM/WHERE pair for a source is built in exactly one place (BuildSource(NpgsqlDbContext, LeaderboardQuery, long)) and every statement is composed from it, so the page, the count and the standing cannot disagree about who is eligible or what the score is.

Parameters are numbered as the fragments are built, so a statement binds exactly the parameters it references. All of them are int or long; nothing here binds a uint, which Npgsql cannot.

Constructors

LeaderboardService(INpgsqlDbContextFactory)

Initializes a new instance of LeaderboardService.

public LeaderboardService(INpgsqlDbContextFactory dbContextFactory)

Parameters

dbContextFactory INpgsqlDbContextFactory

Fields

MaxOffset

Deepest offset the service will read from. A board deeper than this is not browsed by page.

public const int MaxOffset = 100000

Field Value

int

MaxPageRows

Largest page the service will return.

public const int MaxPageRows = 200

Field Value

int

Methods

FetchPageAsync(LeaderboardQuery, int, int, CancellationToken)

A slice of a board, best first, with the board's size.

public Task<DatabaseResult<LeaderboardPageData>> FetchPageAsync(LeaderboardQuery query, int offset, int limit, CancellationToken cancellationToken = default)

Parameters

query LeaderboardQuery

Which board.

offset int

Zero-based position of the first row.

limit int

Rows to return, clamped to 1-200.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<LeaderboardPageData>>

FetchStandingAsync(LeaderboardQuery, long, CancellationToken)

One character's rank and score on a board, wherever it falls.

public Task<DatabaseResult<LeaderboardStandingData>> FetchStandingAsync(LeaderboardQuery query, long characterId, CancellationToken cancellationToken = default)

Parameters

query LeaderboardQuery

Which board.

characterId long

The character.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult<LeaderboardStandingData>>

Remarks

Succeeds with Ranked false when the character is not on the board, which is an ordinary answer and not a failure.