From 4855b9ad01c484ff4283ba79ae1fdd0363025016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Wed, 5 Mar 2025 17:34:52 -0500 Subject: [PATCH 1/2] Revert "rollback: testing to find out if we're getting duplicates" This reverts commit 149e69f5acfc7d8b9d3129500c727324289f049b. --- .../ChatRules/TwitchChatMessageMonitorConsumer.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Nullinside.Api.TwitchBot/ChatRules/TwitchChatMessageMonitorConsumer.cs b/src/Nullinside.Api.TwitchBot/ChatRules/TwitchChatMessageMonitorConsumer.cs index 3254b3b..f36ef69 100644 --- a/src/Nullinside.Api.TwitchBot/ChatRules/TwitchChatMessageMonitorConsumer.cs +++ b/src/Nullinside.Api.TwitchBot/ChatRules/TwitchChatMessageMonitorConsumer.cs @@ -111,14 +111,13 @@ private async void MainLoop() { // Try to get a message from one of the two queues. ChatMessage? message; _queue.TryTake(out message); - + // If we didn't get a message, loop. if (null == message) { Thread.Sleep(LOOP_TIMEOUT); continue; } - LOG.Info("Message received: " + message.Id); string? channel = message.Channel; try { // Sanity check. From 4734835595fb58ab596d06aacddd009d03164402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Wed, 5 Mar 2025 18:19:30 -0500 Subject: [PATCH 2/2] feat: fixing duplicate issue when committing Fixing issue with duplicate exception. closes nullinside-development-group/nullinside-api#70 --- .../Model/NullinsideContextExtensions.cs | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Nullinside.Api.TwitchBot/Model/NullinsideContextExtensions.cs b/src/Nullinside.Api.TwitchBot/Model/NullinsideContextExtensions.cs index db635a8..72977ff 100644 --- a/src/Nullinside.Api.TwitchBot/Model/NullinsideContextExtensions.cs +++ b/src/Nullinside.Api.TwitchBot/Model/NullinsideContextExtensions.cs @@ -168,19 +168,15 @@ await db.TwitchUser.UpsertRange( .On(v => new { v.TwitchId }) .RunAsync(stoppingToken); - db.TwitchBan.AddRange( - bannedUsers.Select(i => new TwitchBan { - ChannelId = channelId, - BannedUserTwitchId = i.Id, - Reason = reason, - Timestamp = DateTime.UtcNow - }).ToList()); - - // Trying to fix bug? - foreach (TwitchBan twitchBan in db.TwitchBan) { - db.Entry(twitchBan).State = EntityState.Added; - } - - await db.SaveChangesAsync(stoppingToken); + await db.TwitchBan.UpsertRange( + bannedUsers.Select(i => new TwitchBan { + ChannelId = channelId, + BannedUserTwitchId = i.Id, + Reason = reason, + Timestamp = DateTime.UtcNow + }).ToList() + ) + .On(v => new { v.ChannelId, v.BannedUserTwitchId, v.Timestamp }) + .RunAsync(stoppingToken); } } \ No newline at end of file