fix: Fix duplicate sync task calls on startup

This commit is contained in:
Mira 2025-05-07 00:14:50 +02:00
parent 6f1155c8c4
commit bbb9935205
Signed by untrusted user who does not match committer: Xorog
GPG key ID: 983798ED9C3E7C36
2 changed files with 12 additions and 3 deletions

@ -1 +1 @@
Subproject commit dadeb77e1667b6785ee8368eb92b2bbe1efba06e Subproject commit 8504368d352bd76e4486f6f3291936c0ae61ad0b

View file

@ -14,10 +14,13 @@ internal static class SyncTasks
{ {
internal static async Task GuildDownloadCompleted(Bot bot, DiscordClient sender, GuildDownloadCompletedEventArgs e) internal static async Task GuildDownloadCompleted(Bot bot, DiscordClient sender, GuildDownloadCompletedEventArgs e)
{ {
_ = Task.Run(async () => if (bot.status.DiscordGuildDownloadCompleted)
{ return;
bot.status.DiscordGuildDownloadCompleted = true; bot.status.DiscordGuildDownloadCompleted = true;
_ = Task.Run(async () =>
{
Log.Information("I'm on {GuildsCount} guilds.", e.Guilds.Count); Log.Information("I'm on {GuildsCount} guilds.", e.Guilds.Count);
_ = Task.Run(async () => _ = Task.Run(async () =>
@ -121,8 +124,14 @@ internal static class SyncTasks
}).Add(bot); }).Add(bot);
} }
internal static DateTime lastSyncTaskTime = DateTime.MinValue;
internal static async Task ExecuteSyncTasks(Bot bot, DiscordShardedClient shardedClient) internal static async Task ExecuteSyncTasks(Bot bot, DiscordShardedClient shardedClient)
{ {
if (lastSyncTaskTime.GetTimespanSince() < TimeSpan.FromSeconds(30))
return;
lastSyncTaskTime = DateTime.UtcNow;
var Guilds = shardedClient.GetGuilds(); var Guilds = shardedClient.GetGuilds();
ObservableList<Task> runningTasks = new(); ObservableList<Task> runningTasks = new();