Hopefully fixed the startup issue

This commit is contained in:
Toastie 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

@ -688,7 +688,7 @@ public abstract class EllieContext : DbContext
x.GuildId, x.GuildId,
x.GreetType x.GreetType
}) })
.IsUnique()); .IsUnique());
modelBuilder.Entity<GreetSettings>(gs => modelBuilder.Entity<GreetSettings>(gs =>
{ {

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,30 +256,40 @@ 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()))
.UpdateAsync(_ => new() .Select(x => x.Id)
{ .ToListAsyncLinqToDB();
Forgiven = true,
ForgivenBy = "expiry" var cleared = await uow.GetTable<Warning>()
}); .Where(x => toClear.Contains(x.Id))
.UpdateAsync(_ => new()
{
Forgiven = true,
ForgivenBy = "expiry"
});
var toDelete = await uow.GetTable<Warning>()
.Where(x => uow.GetTable<GuildConfig>()
.Count(y => y.GuildId == x.GuildId
&& y.WarnExpireHours > 0
&& y.WarnExpireAction == WarnExpireAction.Delete)
> 0
&& x.DateAdded
< DateTime.UtcNow.AddHours(-uow.GetTable<GuildConfig>()
.Where(y => x.GuildId == y.GuildId)
.Select(y => y.WarnExpireHours)
.First()))
.Select(x => x.Id)
.ToListAsyncLinqToDB();
var deleted = await uow.GetTable<Warning>() var deleted = await uow.GetTable<Warning>()
.Where(x => uow.GetTable<GuildConfig>() .Where(x => toDelete.Contains(x.Id))
.Count(y => y.GuildId == x.GuildId .DeleteAsync();
&& y.WarnExpireHours > 0
&& y.WarnExpireAction == WarnExpireAction.Delete)
> 0
&& x.DateAdded
< DateTime.UtcNow.AddHours(-uow.GetTable<GuildConfig>()
.Where(y => x.GuildId == y.GuildId)
.Select(y => y.WarnExpireHours)
.First()))
.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);
} }
} }