Compare commits

...

2 commits

Author SHA1 Message Date
9c94a66323
I apparently updated this file? 2024-09-20 19:27:30 +12:00
e896c14303
Hopefully fixed the startup issue 2024-09-20 19:15:37 +12:00
3 changed files with 36 additions and 26 deletions

View file

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