Skip to content

Commit

Permalink
Allow accurate lookups if beatmap doesn't have many scores
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Oct 28, 2024
1 parent 2c00fd8 commit 2dc5aac
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions GlobalRankLookupCache/Controllers/BeatmapItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,29 @@ public BeatmapItem(int beatmapId, string highScoresTable)
using (var db = await Program.GetDatabaseConnection())
using (var cmd = db.CreateCommand())
{
Interlocked.Increment(ref RankLookupController.Misses);

cmd.CommandTimeout = 10;
cmd.CommandText = $"select count(*) from {highScoresTable} where beatmap_id = {beatmapId} and score > {score} and hidden = 0";
int pos = (int)(long)(await cmd.ExecuteScalarAsync())!;

cmd.CommandTimeout = 10;
Interlocked.Increment(ref RankLookupController.Misses);

cmd.CommandText = $"select count(*) from {highScoresTable} where beatmap_id = {beatmapId} and hidden = 0";
int total = (int)(long)(await cmd.ExecuteScalarAsync())!;

return (pos, total, false);
if (total < 2000)
{
cmd.CommandText = $"select count(DISTINCT user_id) from {highScoresTable} where beatmap_id = {beatmapId} and hidden = 0";
total = (int)(long)(await cmd.ExecuteScalarAsync())!;

cmd.CommandText = $"select count(DISTINCT user_id) from {highScoresTable} where beatmap_id = {beatmapId} and score > {score} and hidden = 0";
int pos = (int)(long)(await cmd.ExecuteScalarAsync())!;
return (pos, total, true);
}
else
{
cmd.CommandText = $"select count(*) from {highScoresTable} where beatmap_id = {beatmapId} and score > {score} and hidden = 0";
int pos = (int)(long)(await cmd.ExecuteScalarAsync())!;

return (pos, total, false);
}
}
}

Expand Down

0 comments on commit 2dc5aac

Please sign in to comment.