feat: clear timeouts that never get logged

This commit is contained in:
sam 2024-11-13 15:14:22 +01:00
parent 0564206bf7
commit 254a50da4d
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
2 changed files with 18 additions and 3 deletions

View file

@ -5,7 +5,9 @@ using Remora.Rest.Core;
namespace Catalogger.Backend.Database.Repositories;
public class TimeoutRepository(DatabaseConnection conn) : IDisposable, IAsyncDisposable
public class TimeoutRepository(DatabaseConnection conn, IClock clock)
: IDisposable,
IAsyncDisposable
{
public async Task<DiscordTimeout?> GetAsync(int id) =>
await conn.QueryFirstOrDefaultAsync<DiscordTimeout>(
@ -62,6 +64,12 @@ public class TimeoutRepository(DatabaseConnection conn) : IDisposable, IAsyncDis
new { GuildId = guildId.Value, UserId = userId.Value }
);
public async Task<int> RemoveExpiredTimeoutsAsync() =>
await conn.ExecuteAsync(
"delete from timeouts where until < @Expiry",
new { Expiry = clock.GetCurrentInstant() - Duration.FromMinutes(5) }
);
public void Dispose()
{
conn.Dispose();