Skip to content

Commit

Permalink
Merge pull request #251 from peppy/fix-rank-off-by-one
Browse files Browse the repository at this point in the history
Never include self when querying for current rank
  • Loading branch information
smoogipoo authored Apr 2, 2024
2 parents 3704611 + 1f5abfe commit ee0313c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ public async Task UpdateUserStatsAsync(UserStats userStats, int rulesetId, MySql
private static async Task updateGlobalRank(UserStats userStats, MySqlConnection connection, MySqlTransaction? transaction, LegacyDatabaseHelper.RulesetDatabaseInfo dbInfo)
{
// User's current global rank.
userStats.rank_score_index = (await connection.QuerySingleAsync<int>($"SELECT COUNT(*) FROM {dbInfo.UserStatsTable} WHERE rank_score > {userStats.rank_score}", transaction: transaction))
+ 1;
userStats.rank_score_index = await connection.QuerySingleAsync<int>($"SELECT COUNT(*) FROM {dbInfo.UserStatsTable} WHERE rank_score > @rankScoreCutoff AND user_id != @userId",
new
{
userId = userStats.user_id,
rankScoreCutoff = userStats.rank_score,
}, transaction: transaction) + 1;

// User's historical best rank (ever).
int userHistoricalHighestRank = await connection.QuerySingleOrDefaultAsync<int?>("SELECT `rank` FROM `osu_user_performance_rank_highest` WHERE `user_id` = @userId AND `mode` = @mode",
Expand Down

0 comments on commit ee0313c

Please sign in to comment.