feat: rate limit emails to two per address per hour

This commit is contained in:
sam 2024-12-11 20:42:48 +01:00
parent 5cb3faa92b
commit ff8d53814d
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
6 changed files with 189 additions and 49 deletions

View file

@ -33,13 +33,24 @@ public class DataCleanupService(
public async Task InvokeAsync(CancellationToken ct = default)
{
_logger.Information("Cleaning up expired users");
_logger.Debug("Cleaning up sent email cache");
await CleanEmailsAsync(ct);
_logger.Debug("Cleaning up expired users");
await CleanUsersAsync(ct);
_logger.Information("Cleaning up expired data exports");
_logger.Debug("Cleaning up expired data exports");
await CleanExportsAsync(ct);
}
private async Task CleanEmailsAsync(CancellationToken ct = default)
{
Instant expiry = clock.GetCurrentInstant() - Duration.FromHours(2);
int count = await db.SentEmails.Where(e => e.SentAt < expiry).ExecuteDeleteAsync(ct);
if (count != 0)
_logger.Information("Deleted {Count} entries from the sent email cache", expiry);
}
private async Task CleanUsersAsync(CancellationToken ct = default)
{
Instant selfDeleteExpires = clock.GetCurrentInstant() - User.DeleteAfter;