From 66e483be6f1202ee60b888b38fd3c8f670f05c4c Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 25 Mar 2021 18:02:44 +0000 Subject: [PATCH] Fix NullReferenceError when HasValue is true but Value is null --- PluralKit.Bot/Services/LastMessageCacheService.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/PluralKit.Bot/Services/LastMessageCacheService.cs b/PluralKit.Bot/Services/LastMessageCacheService.cs index 9ebbbc50..1a8b1d17 100644 --- a/PluralKit.Bot/Services/LastMessageCacheService.cs +++ b/PluralKit.Bot/Services/LastMessageCacheService.cs @@ -5,11 +5,7 @@ using Myriad.Types; namespace PluralKit.Bot { - // Doing things like this instead of enabling D.NET's message cache because the message cache is, let's face it, - // not particularly efficient? It allocates a dictionary *and* a queue for every single channel (500k in prod!) - // whereas this is, worst case, one dictionary *entry* of a single ulong per channel, and one dictionary instance - // on the whole instance, total. Yeah, much more efficient. - // TODO: is this still needed after the D#+ migration? + // TODO: Should this be moved to Myriad.Cache? public class LastMessageCacheService { private readonly IDictionary _cache = new ConcurrentDictionary(); @@ -34,8 +30,8 @@ namespace PluralKit.Bot public CachedMessage(Message msg) { mid = msg.Id; - if (msg.ReferencedMessage.HasValue) + if (msg.ReferencedMessage.Value != null) referenced_message = msg.ReferencedMessage.Value.Id; } } -} \ No newline at end of file +}