Skip to content

Commit 0b8e2e5

Browse files
fix: concurrency issue when saving records
I don't have high hopes for this fix but it was suggested here and I can't completely ignore the similiarity in how odd this is: https://learn.microsoft.com/en-us/answers/questions/1186074/database-update-insert-fails So we shouldn't have the possibility of concurrency issues here because we are simply inserting everything. Worse case scenario we would end up with double entries for the same ban. Yet for some reason it seems to think we're modifying entries when we're supposed to be inserting them. As such it's reasonable to assume swapping the state to added (despite the fact that the "AddRange" method is supposed to do that for us) might resolve the issue. Again, I'm not entirely hopeful but I'm willing to try. Since the issue is intermittent we have to test in prod.
1 parent 02ea0b9 commit 0b8e2e5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Nullinside.Api.TwitchBot/Model/NullinsideContextExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@ await db.TwitchUser.UpsertRange(
174174
BannedUserTwitchId = i.Id,
175175
Reason = reason,
176176
Timestamp = DateTime.UtcNow
177-
}));
177+
}).ToList());
178+
179+
// Trying to fix bug?
180+
foreach (TwitchBan twitchBan in db.TwitchBan) {
181+
db.Entry(twitchBan).State = EntityState.Added;
182+
}
183+
178184
await db.SaveChangesAsync(stoppingToken);
179185
}
180186
}

src/nullinside-api

0 commit comments

Comments
 (0)