Change editor rule

This commit is contained in:
2026-09-24 13:24:43 +02:00
parent 16478678b5
commit 73e37dbecd
401 changed files with 14735 additions and 12995 deletions
@@ -3,36 +3,37 @@ using Microsoft.Extensions.Logging;
using Musify.Application.Configuration;
using Musify.Application.Contracts;
namespace Musify.Application.UploadIntents;
/// <summary>Deletes temporary upload objects that nobody claimed within the retention window.</summary>
public record DeleteStaleTempUploadsCommand : ICommand<int>;
public class DeleteStaleTempUploadsCommandHandler(
IStorageService storageService,
ApplicationStorageConfiguration storageConfiguration,
UploadIntentConfiguration uploadIntentConfiguration,
ILogger<DeleteStaleTempUploadsCommandHandler> logger)
: ICommandHandler<DeleteStaleTempUploadsCommand, int>
namespace Musify.Application.UploadIntents
{
public async ValueTask<int> Handle(DeleteStaleTempUploadsCommand request, CancellationToken cancellationToken)
/// <summary>Deletes temporary upload objects that nobody claimed within the retention window.</summary>
public record DeleteStaleTempUploadsCommand : ICommand<int>;
public class DeleteStaleTempUploadsCommandHandler(
IStorageService storageService,
ApplicationStorageConfiguration storageConfiguration,
UploadIntentConfiguration uploadIntentConfiguration,
ILogger<DeleteStaleTempUploadsCommandHandler> logger)
: ICommandHandler<DeleteStaleTempUploadsCommand, int>
{
var cutOff = DateTime.UtcNow.AddDays(-uploadIntentConfiguration.TempUploadsRetentionDays);
var deleted = 0;
await foreach (var (key, lastModified) in storageService.ListObjectsAsync(
storageConfiguration.Bucket, uploadIntentConfiguration.TempRootPrefix, cancellationToken))
public async ValueTask<int> Handle(DeleteStaleTempUploadsCommand request, CancellationToken cancellationToken)
{
if (lastModified >= cutOff)
continue;
var cutOff = DateTime.UtcNow.AddDays(-uploadIntentConfiguration.TempUploadsRetentionDays);
var deleted = 0;
await storageService.RemoveFileAsync(storageConfiguration.Bucket, key, cancellationToken);
deleted++;
await foreach (var (key, lastModified) in storageService.ListObjectsAsync(
storageConfiguration.Bucket, uploadIntentConfiguration.TempRootPrefix, cancellationToken))
{
if (lastModified >= cutOff)
continue;
await storageService.RemoveFileAsync(storageConfiguration.Bucket, key, cancellationToken);
deleted++;
}
if (deleted > 0)
logger.LogInformation("Deleted {Deleted} orphaned temp uploads", deleted);
return deleted;
}
if (deleted > 0)
logger.LogInformation("Deleted {Deleted} orphaned temp uploads", deleted);
return deleted;
}
}
@@ -5,42 +5,43 @@ using Musify.Application.Configuration;
using Musify.Application.Contracts;
using Musify.Domain.ValueObjects;
namespace Musify.Application.UploadIntents;
/// <summary>Marks overdue upload intents as expired and deletes the ones expired for longer than the retention window.</summary>
public record ExpireUploadIntentsCommand : ICommand<int>;
public class ExpireUploadIntentsCommandHandler(
IDatabase database,
UploadIntentConfiguration uploadIntentConfiguration,
ILogger<ExpireUploadIntentsCommandHandler> logger)
: ICommandHandler<ExpireUploadIntentsCommand, int>
namespace Musify.Application.UploadIntents
{
public async ValueTask<int> Handle(ExpireUploadIntentsCommand request, CancellationToken cancellationToken)
/// <summary>Marks overdue upload intents as expired and deletes the ones expired for longer than the retention window.</summary>
public record ExpireUploadIntentsCommand : ICommand<int>;
public class ExpireUploadIntentsCommandHandler(
IDatabase database,
UploadIntentConfiguration uploadIntentConfiguration,
ILogger<ExpireUploadIntentsCommandHandler> logger)
: ICommandHandler<ExpireUploadIntentsCommand, int>
{
var now = DateTime.UtcNow;
public async ValueTask<int> Handle(ExpireUploadIntentsCommand request, CancellationToken cancellationToken)
{
var now = DateTime.UtcNow;
var expiredIntents = await database.UploadIntents
.Where(intent => intent.Status == UploadIntentStatus.Issued && intent.ExpiresAt < now)
.ToListAsync(cancellationToken);
var expiredIntents = await database.UploadIntents
.Where(intent => intent.Status == UploadIntentStatus.Issued && intent.ExpiresAt < now)
.ToListAsync(cancellationToken);
foreach (var intent in expiredIntents)
intent.Status = UploadIntentStatus.Expired;
foreach (var intent in expiredIntents)
intent.Status = UploadIntentStatus.Expired;
var retentionCutoff = now.AddDays(-uploadIntentConfiguration.ExpiredIntentsRetentionDays);
var oldExpiredIntents = await database.UploadIntents
.Where(intent => intent.Status == UploadIntentStatus.Expired && intent.ExpiresAt < retentionCutoff)
.ToListAsync(cancellationToken);
var retentionCutoff = now.AddDays(-uploadIntentConfiguration.ExpiredIntentsRetentionDays);
var oldExpiredIntents = await database.UploadIntents
.Where(intent => intent.Status == UploadIntentStatus.Expired && intent.ExpiresAt < retentionCutoff)
.ToListAsync(cancellationToken);
database.UploadIntents.RemoveRange(oldExpiredIntents);
database.UploadIntents.RemoveRange(oldExpiredIntents);
if (expiredIntents.Count == 0 && oldExpiredIntents.Count == 0)
return 0;
if (expiredIntents.Count == 0 && oldExpiredIntents.Count == 0)
return 0;
await database.SaveChangesAsync(cancellationToken);
logger.LogInformation("Marked {Expired} upload intents as expired and deleted {Deleted} old ones",
expiredIntents.Count, oldExpiredIntents.Count);
await database.SaveChangesAsync(cancellationToken);
logger.LogInformation("Marked {Expired} upload intents as expired and deleted {Deleted} old ones",
expiredIntents.Count, oldExpiredIntents.Count);
return expiredIntents.Count + oldExpiredIntents.Count;
return expiredIntents.Count + oldExpiredIntents.Count;
}
}
}