From 0eb62b5421bc29eabd6ebb32a899f35ece97ba9a Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 24 Dec 2022 12:17:33 +0000 Subject: [PATCH 1/5] Select from cached winnerIds variable --- Present/Services/GiveawayService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Present/Services/GiveawayService.cs b/Present/Services/GiveawayService.cs index 804f43f..f35fa3e 100644 --- a/Present/Services/GiveawayService.cs +++ b/Present/Services/GiveawayService.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using CSharpVitamins; using DSharpPlus; @@ -201,7 +201,7 @@ public DiscordEmbedBuilder CreateGiveawayInformationEmbed(Giveaway giveaway) List winnerIds = giveaway.WinnerIds; if (winnerIds.Count > 0) { - string winnerList = string.Join('\n', giveaway.WinnerIds.Select(w => $"• {MentionUtility.MentionUser(w)} ({w})")); + string winnerList = string.Join('\n', winnerIds.Select(w => $"• {MentionUtility.MentionUser(w)} ({w})")); embed.AddField(EmbedStrings.Winner.ToQuantity(winnerIds.Count), winnerList); } From 46624365b6444c8a4497a7b7659263af18ac0732 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 24 Dec 2022 12:17:46 +0000 Subject: [PATCH 2/5] Throw on null giveaway in EndGiveawayAsync --- Present/Services/GiveawayService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Present/Services/GiveawayService.cs b/Present/Services/GiveawayService.cs index f35fa3e..e72db91 100644 --- a/Present/Services/GiveawayService.cs +++ b/Present/Services/GiveawayService.cs @@ -268,6 +268,8 @@ public DiscordEmbed CreateGiveawayPublicEmbed(Giveaway giveaway) /// is . public async Task EndGiveawayAsync(Giveaway giveaway) { + ArgumentNullException.ThrowIfNull(giveaway); + giveaway.EndHandled = true; giveaway.EndTime = DateTimeOffset.UtcNow; From 3bbaab440a512b0c0005c120864642a9f0204538 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 24 Dec 2022 12:28:15 +0000 Subject: [PATCH 3/5] Trace log giveaway cache load --- Present/Services/GiveawayService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Present/Services/GiveawayService.cs b/Present/Services/GiveawayService.cs index e72db91..03d6a23 100644 --- a/Present/Services/GiveawayService.cs +++ b/Present/Services/GiveawayService.cs @@ -658,6 +658,8 @@ public bool ValidateUser(ulong userId, DiscordGuild guild, [NotNullWhen(true)] o private async Task UpdateFromDatabaseAsync(CancellationToken cancellationToken) { + Logger.Info("Caching giveaways from the database..."); + await using AsyncServiceScope scope = _serviceScopeFactory.CreateAsyncScope(); await using var context = scope.ServiceProvider.GetRequiredService(); await context.Database.EnsureCreatedAsync(cancellationToken: cancellationToken).ConfigureAwait(false); From f33a30777c1f800aefd609f3b555132dc6a2871b Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 24 Dec 2022 16:41:36 +0000 Subject: [PATCH 4/5] Read to listCount, not list.Count (fixes #1) --- Present/Data/ValueConverters/UInt64ListToBytesConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Present/Data/ValueConverters/UInt64ListToBytesConverter.cs b/Present/Data/ValueConverters/UInt64ListToBytesConverter.cs index 8346d06..b8bb135 100644 --- a/Present/Data/ValueConverters/UInt64ListToBytesConverter.cs +++ b/Present/Data/ValueConverters/UInt64ListToBytesConverter.cs @@ -31,7 +31,7 @@ private static List FromBytes(byte[] bytes) var list = new List(listCount); - for (var index = 0; index < list.Count; index++) + for (var index = 0; index < listCount; index++) list.Add(reader.ReadUInt64()); return list; From b92ac2fb18f601d37c587fad9589e07f8e651736 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 24 Dec 2022 16:41:55 +0000 Subject: [PATCH 5/5] Bump to 1.1.0 --- Present/Present.csproj | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Present/Present.csproj b/Present/Present.csproj index 2d92b80..ee1abe1 100644 --- a/Present/Present.csproj +++ b/Present/Present.csproj @@ -6,7 +6,7 @@ enable enable Linux - 1.0.0 + 1.1.0 @@ -28,22 +28,22 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - + + + + + + + +