From 21bef1a98e633ecdeca483143a5c4cd0669fbce2 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 3 Jan 2022 04:31:56 +0100 Subject: [PATCH] - Possible small fix for .prune ratelimiting - Use .WhenAll extension instead of Task.WhenAll in a few more places --- src/NadekoBot.Tests/GroupGreetTests.cs | 5 +++-- src/NadekoBot/Modules/Administration/Prune/PruneService.cs | 2 +- src/NadekoBot/Modules/Administration/Self/SelfService.cs | 4 ++-- src/NadekoBot/_Extensions/EnumerableExtensions.cs | 2 -- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/NadekoBot.Tests/GroupGreetTests.cs b/src/NadekoBot.Tests/GroupGreetTests.cs index 84fd35b39..e58b4f6b7 100644 --- a/src/NadekoBot.Tests/GroupGreetTests.cs +++ b/src/NadekoBot.Tests/GroupGreetTests.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using NadekoBot.Extensions; using NadekoBot.Services; using NUnit.Framework; @@ -62,8 +63,8 @@ namespace NadekoBot.Tests _grouper.CreateOrAdd(0, 5); // add 15 items - await Task.WhenAll(Enumerable.Range(10, 15) - .Select(x => Task.Run(() => _grouper.CreateOrAdd(0, x)))); + await Enumerable.Range(10, 15) + .Select(x => Task.Run(() => _grouper.CreateOrAdd(0, x))).WhenAll(); // get 5 at most _grouper.ClearGroup(0, 5, out var items); diff --git a/src/NadekoBot/Modules/Administration/Prune/PruneService.cs b/src/NadekoBot/Modules/Administration/Prune/PruneService.cs index 4f21d0669..5a511399c 100644 --- a/src/NadekoBot/Modules/Administration/Prune/PruneService.cs +++ b/src/NadekoBot/Modules/Administration/Prune/PruneService.cs @@ -46,7 +46,7 @@ public class PruneService : INService await Task.WhenAll(Task.Delay(1000), channel.DeleteMessagesAsync(bulkDeletable)); foreach (var group in singleDeletable.Chunk(5)) - await Task.WhenAll(Task.Delay(1000), group.Select(x => x.DeleteAsync()).WhenAll()); + await Task.WhenAll(Task.Delay(5000), group.Select(x => x.DeleteAsync()).WhenAll()); //this isn't good, because this still work as if i want to remove only specific user's messages from the last //100 messages, Maybe this needs to be reduced by msgs.Length instead of 100 diff --git a/src/NadekoBot/Modules/Administration/Self/SelfService.cs b/src/NadekoBot/Modules/Administration/Self/SelfService.cs index 1cf839fbe..5bc7a0504 100644 --- a/src/NadekoBot/Modules/Administration/Self/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Self/SelfService.cs @@ -170,14 +170,14 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService private async Task LoadOwnerChannels() { - var channels = await Task.WhenAll(_creds.OwnerIds.Select(id => + var channels = await _creds.OwnerIds.Select(id => { var user = _client.GetUser(id); if (user is null) return Task.FromResult(null); return user.CreateDMChannelAsync(); - })); + }).WhenAll(); ownerChannels = channels.Where(x => x is not null) .ToDictionary(x => x.Recipient.Id, x => x) diff --git a/src/NadekoBot/_Extensions/EnumerableExtensions.cs b/src/NadekoBot/_Extensions/EnumerableExtensions.cs index 6fbba0ab4..edcfab4ba 100644 --- a/src/NadekoBot/_Extensions/EnumerableExtensions.cs +++ b/src/NadekoBot/_Extensions/EnumerableExtensions.cs @@ -88,8 +88,6 @@ public static class EnumerableExtensions where T : class, IIndexed => new(enumerable); - // todo use this extension instead of Task.WhenAll - /// /// Creates a task that will complete when all of the objects in an enumerable /// collection have completed