Skip to content

Commit

Permalink
fuck parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
sylveonnotdeko committed Apr 16, 2024
1 parent a436b9e commit 94c1495
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/Mewdeko/Modules/Utility/Services/MessageRepeaterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ public async Task OnReadyAsync()
await using var uow = db.GetDbContext();

var repeaters = new Dictionary<ulong, ConcurrentDictionary<int, RepeatRunner>>();
await Parallel.ForEachAsync(client.Guilds, new ParallelOptions
{
MaxDegreeOfParallelism = 8
}, async (gc, cancellationToken) =>
foreach (var gc in client.Guilds)
{
try
{
var config = await gss.GetGuildConfig(gc.Id);
var idToRepeater = config.GuildRepeaters
.Where(gr => gr.DateAdded != null)
.Select(gr => new KeyValuePair<int, RepeatRunner>(
gr.Id,
new RepeatRunner(client, gc, gr, this)))
.GroupBy(x => x.Key)
.ToDictionary(g => g.Key, g => g.First().Value)
.Where(gr => gr.DateAdded is not null)
.Select(gr =>
new KeyValuePair<int, RepeatRunner>(gr.Id, new RepeatRunner(client, gc, gr, this)))
.ToDictionary(x => x.Key, y => y.Value)
.ToConcurrent();

repeaters.TryAdd(gc.Id, idToRepeater);
Expand All @@ -53,7 +48,7 @@ public async Task OnReadyAsync()
{
Log.Error(ex, "Failed to load repeaters on Guild {0}", gc.Id);
}
});
}

Repeaters = repeaters.ToConcurrent();
RepeaterReady = true;
Expand Down

0 comments on commit 94c1495

Please sign in to comment.