Previously we did not specify a rank, which made it default to 0. Which messed up the overall ranking.
What we do now is try to calculate the rank based on the number of players by fetching a count.
I'm very unfamiliar with this ORM, I tried using a raw query initially but got it to work this way. Very open to suggestions.
It's not perfect but it solves our case while not handling an edge case -> race condition when multiple users create players at the same time and count results are not correct -> but this gets solved when the ranking gets recalculated.
On a second thought:
This is still not very nice because we assume that other players will always have better ranks than a new player which might not be the case 🤔.
I'm fine with leaving the fix like this because we'll not break the top rankings, but when we do store scores in the database and sort by that when fetching users this problem will not be a problem anymore.
Previously we did not specify a rank, which made it default to 0. Which messed up the overall ranking.
What we do now is try to calculate the rank based on the number of players by fetching a count.
I'm very unfamiliar with this ORM, I tried using a raw query initially but got it to work this way. Very open to suggestions.
It's not perfect but it solves our case while not handling an edge case -> race condition when multiple users create players at the same time and count results are not correct -> but this gets solved when the ranking gets recalculated.
On a second thought:
This is still not very nice because we assume that other players will always have better ranks than a new player which might not be the case 🤔. I'm fine with leaving the fix like this because we'll not break the top rankings, but when we do store scores in the database and sort by that when fetching users this problem will not be a problem anymore.
new player getting lowest rank: