Hopefully fixed the startup issue

This commit is contained in:
Toastie (DCS Team) 2024-09-20 19:15:37 +12:00
parent 0d6b4da1ce
commit e896c14303
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
2 changed files with 29 additions and 19 deletions

View file

@ -244,7 +244,7 @@ public class UserPunishService : IEService, IReadyExecutor
{
await using var uow = _db.GetDbContext();
var cleared = await uow.GetTable<Warning>()
var toClear = await uow.GetTable<Warning>()
.Where(x => uow.GetTable<GuildConfig>()
.Count(y => y.GuildId == x.GuildId
&& y.WarnExpireHours > 0
@ -256,13 +256,18 @@ public class UserPunishService : IEService, IReadyExecutor
.Where(y => x.GuildId == y.GuildId)
.Select(y => y.WarnExpireHours)
.First()))
.Select(x => x.Id)
.ToListAsyncLinqToDB();
var cleared = await uow.GetTable<Warning>()
.Where(x => toClear.Contains(x.Id))
.UpdateAsync(_ => new()
{
Forgiven = true,
ForgivenBy = "expiry"
});
var deleted = await uow.GetTable<Warning>()
var toDelete = await uow.GetTable<Warning>()
.Where(x => uow.GetTable<GuildConfig>()
.Count(y => y.GuildId == x.GuildId
&& y.WarnExpireHours > 0
@ -273,13 +278,18 @@ public class UserPunishService : IEService, IReadyExecutor
.Where(y => x.GuildId == y.GuildId)
.Select(y => y.WarnExpireHours)
.First()))
.Select(x => x.Id)
.ToListAsyncLinqToDB();
var deleted = await uow.GetTable<Warning>()
.Where(x => toDelete.Contains(x.Id))
.DeleteAsync();
if (cleared > 0 || deleted > 0)
{
Log.Information("Cleared {ClearedWarnings} warnings and deleted {DeletedWarnings} warnings due to expiry",
cleared,
deleted);
toDelete.Count);
}
}