Skip to content

Player leaderboard position does not consider ties #83

@cetteup

Description

@cetteup

It is possible that two players have e.g. the same overall score, meaning they tie for a leaderboard position. For the leaderboard itself, that tie is broken by additionally sorting by name.

$query = "SELECT id, name, rank_id, country, time, score FROM player WHERE score > 0
ORDER BY score DESC, name DESC LIMIT " . $min . ", " . $max;

However, the tiebreaker is not applied when determining a player's position on the leaderboard directly.

$query = "SELECT COUNT(id) FROM player WHERE score > %d";

This mismatch results in a potentially incorrect and non-unique leaderboard position being returned for the player, since every player with the same score will be placed at the same position by the 2nd query.

A quick example. The actual leaderboard might be (name is sorted DESC to break ties):

Pos Nick Score
1 alpha 1000
2 charlie 900
3 bravo 900

Requesting the positions of bravo or charlie will return 2, since only alpha has a greater score.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions