Skip to content

Commit

Permalink
Don't reuse HttpClient for osu!api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
matte-ek committed Jul 28, 2023
1 parent 83ea951 commit 99eb4b0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions BanchoMultiplayerBot/OsuApi/OsuApiWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ namespace BanchoMultiplayerBot.OsuApi;
/// </summary>
public class OsuApiWrapper
{
private static readonly HttpClient Client = new();
private readonly string _osuApiKey;
private readonly Bot _bot;

public OsuApiWrapper(Bot bot, string osuApiKey)
{
_bot = bot;
_osuApiKey = osuApiKey;

Client.Timeout = TimeSpan.FromSeconds(5);
}

public async Task<BeatmapModel?> GetBeatmapInformation(int beatmapId, int mods = 0)
{
using var httpClient = new HttpClient();
using var _ = _bot.RuntimeInfo.Statistics.ApiRequestTime.NewTimer();

_bot.RuntimeInfo.Statistics.ApiRequests.Inc();

httpClient.Timeout = TimeSpan.FromSeconds(5);

try
{
var result =
await Client.GetAsync($"https://osu.ppy.sh/api/get_beatmaps?k={_osuApiKey}&b={beatmapId}&mods={mods}");
var result = await httpClient.GetAsync($"https://osu.ppy.sh/api/get_beatmaps?k={_osuApiKey}&b={beatmapId}&mods={mods}");

if (!result.IsSuccessStatusCode)
{
Expand Down

0 comments on commit 99eb4b0

Please sign in to comment.