Skip to content

Commit

Permalink
chore: Add delays to data fetching to protect us from being banned fr…
Browse files Browse the repository at this point in the history
…om the API
  • Loading branch information
itssimple committed Nov 7, 2024
1 parent 7b42d04 commit ecb5ea7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions CFDiscordBot/CFDiscordBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CurseForge.APIClient" Version="2.2.0" />
<PackageReference Include="Discord.Net" Version="3.13.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="CurseForge.APIClient" Version="3.0.0" />
<PackageReference Include="Discord.Net" Version="3.16.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CFDiscordBot/DiscordBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private async Task DiscordClient_ShardReady(DiscordSocketClient _shardClient)
await interactionService.AddModulesAsync(Assembly.GetEntryAssembly(), serviceProvider);
await interactionService.RegisterCommandsGloballyAsync(true);

discordClient.InteractionCreated += DiscordClient_InteractionCreated; ;
discordClient.InteractionCreated += DiscordClient_InteractionCreated;

logger.LogInformation("Slash commands registered");
}
Expand Down
8 changes: 4 additions & 4 deletions CFLookup/CFLookup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.9" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.15" />
<PackageReference Include="Hangfire.Dashboard.BasicAuthorization" Version="1.0.2" />
<PackageReference Include="Hangfire.Redis.StackExchange" Version="1.9.3" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.5" />
<PackageReference Include="NSec.Cryptography" Version="22.4.0" />
<PackageReference Include="CurseForge.APIClient" Version="2.2.0" />
<PackageReference Include="StackExchange.Redis" Version="2.7.17" />
<PackageReference Include="NSec.Cryptography" Version="24.4.0" />
<PackageReference Include="CurseForge.APIClient" Version="3.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.16" />
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties wwwroot_4manifest_1json__JsonSchema="https://json.schemastore.org/web-manifest-combined.json" /></VisualStudio></ProjectExtensions>
Expand Down
5 changes: 5 additions & 0 deletions CFLookup/Jobs/GetLatestUpdatedModPerGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static async Task RunAsync(PerformContext context)

var allGames = new List<Game>();
var games = await cfClient.GetGamesAsync();
await Task.Delay(100);
if (games != null && games.Pagination.ResultCount > 0)
{
allGames.AddRange(games.Data);
Expand All @@ -36,6 +37,7 @@ public static async Task RunAsync(PerformContext context)
{
index += games.Pagination.PageSize;
games = await cfClient.GetGamesAsync(index);
await Task.Delay(100);
allGames.AddRange(games.Data);
}
}
Expand Down Expand Up @@ -206,6 +208,7 @@ public static async Task RunAsync(PerformContext context)
{
allGames.Add(game.Data);
}
await Task.Delay(100);
}
}

Expand All @@ -214,6 +217,8 @@ public static async Task RunAsync(PerformContext context)
Console.WriteLine($"Starting to check for latest updated mod for {game.Name} (GameId: {game.Id})");
await _db.StringSetAsync($"cf-game-{game.Id}", JsonSerializer.Serialize(game), TimeSpan.FromDays(1));

await Task.Delay(100);

var latestUpdatedMod = await cfClient.SearchModsAsync(game.Id, sortField: ModsSearchSortField.LastUpdated, sortOrder: ModsSearchSortOrder.Descending, pageSize: 1);
if (latestUpdatedMod != null && latestUpdatedMod.Pagination.ResultCount > 0)
{
Expand Down

0 comments on commit ecb5ea7

Please sign in to comment.