Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Track DavItems still present in History table.
nzbdav-dev1409a75eaaa7
diff --git a/backend/Database/DavDatabaseContext.cs b/backend/Database/DavDatabaseContext.csindex d17608e1..b1d46a27 100644--- a/backend/Database/DavDatabaseContext.cs+++ b/backend/Database/DavDatabaseContext.cs@@ -32,6 +32,7 @@ public sealed class DavDatabaseContext() : DbContext(Options.Value)public DbSet<HealthCheckStat> HealthCheckStats => Set<HealthCheckStat>();public DbSet<ConfigItem> ConfigItems => Set<ConfigItem>();public DbSet<BlobCleanupItem> BlobCleanupItems => Set<BlobCleanupItem>();+ public DbSet<HistoryCleanupItem> HistoryCleanupItems => Set<HistoryCleanupItem>();// blob itemspublic List<DavNzbFile> BlobNzbFiles = [];@@ -118,6 +119,10 @@ public sealed class DavDatabaseContext() : DbContext(Options.Value).ValueGeneratedNever().IsRequired(false);+ e.Property(i => i.HistoryItemId)+ .ValueGeneratedNever()+ .IsRequired(false);+e.HasOne(i => i.Parent).WithMany(p => p.Children).HasForeignKey(i => i.ParentId)@@ -128,7 +133,9 @@ public sealed class DavDatabaseContext() : DbContext(Options.Value)e.HasIndex(i => new { i.IdPrefix, i.Type });- e.HasIndex(i => new { i.Type, i.NextHealthCheck, i.ReleaseDate, i.Id });+ e.HasIndex(i => new { i.Type, i.HistoryItemId, i.NextHealthCheck, i.ReleaseDate, i.Id });++ e.HasIndex(i => new { i.HistoryItemId });});// DavNzbFile@@ -430,6 +437,16 @@ public sealed class DavDatabaseContext() : DbContext(Options.Value)e.Property(i => i.Id).ValueGeneratedNever();});++ // HistoryCleanupItem+ b.Entity<HistoryCleanupItem>(e =>+ {+ e.ToTable("HistoryCleanupItems");+ e.HasKey(i => i.Id);++ e.Property(i => i.Id)+ .ValueGeneratedNever();+ });}public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())diff --git a/backend/Database/Migrations/20260201023253_Add-HistoryItemId-To-DavItems-Table.Designer.cs b/backend/Database/Migrations/20260201023253_Add-HistoryItemId-To-DavItems-Table.Designer.csnew file mode 100644index 00000000..bca8b18d--- /dev/null+++ b/backend/Database/Migrations/20260201023253_Add-HistoryItemId-To-DavItems-Table.Designer.cs@@ -0,0 +1,417 @@+// <auto-generated />+using System;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;+using NzbWebDAV.Database;++#nullable disable++namespace NzbWebDAV.Database.Migrations+{+ [DbContext(typeof(DavDatabaseContext))]+ [Migration("20260201023253_Add-HistoryItemId-To-DavItems-Table")]+ partial class AddHistoryItemIdToDavItemsTable+ {+ /// <inheritdoc />+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "10.0.1");++ modelBuilder.Entity("NzbWebDAV.Database.Models.Account", b =>+ {+ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.Property<string>("Username")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("RandomSalt")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Type", "Username");++ b.ToTable("Accounts", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.BlobCleanupItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("BlobCleanupItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.ConfigItem", b =>+ {+ b.Property<string>("ConfigName")+ .HasColumnType("TEXT");++ b.Property<string>("ConfigValue")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("ConfigName");++ b.ToTable("ConfigItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<Guid?>("FileBlobId")+ .HasColumnType("TEXT");++ b.Property<long?>("FileSize")+ .HasColumnType("INTEGER");++ b.Property<Guid?>("HistoryItemId")+ .HasColumnType("TEXT");++ b.Property<string>("IdPrefix")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<long?>("LastHealthCheck")+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<long?>("NextHealthCheck")+ .HasColumnType("INTEGER");++ b.Property<Guid?>("ParentId")+ .HasColumnType("TEXT");++ b.Property<string>("Path")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<long?>("ReleaseDate")+ .HasColumnType("INTEGER");++ b.Property<int>("SubType")+ .HasColumnType("INTEGER");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("HistoryItemId");++ b.HasIndex("IdPrefix", "Type");++ b.HasIndex("ParentId", "Name")+ .IsUnique();++ b.HasIndex("Type", "HistoryItemId", "NextHealthCheck", "ReleaseDate", "Id");++ b.ToTable("DavItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavMultipartFile", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("Metadata")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("DavMultipartFiles", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavNzbFile", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("SegmentIds")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("DavNzbFiles", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavRarFile", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("RarParts")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("DavRarFiles", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.HealthCheckResult", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<long>("CreatedAt")+ .HasColumnType("INTEGER");++ b.Property<Guid>("DavItemId")+ .HasColumnType("TEXT");++ b.Property<string>("Message")+ .HasColumnType("TEXT");++ b.Property<string>("Path")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<int>("RepairStatus")+ .HasColumnType("INTEGER");++ b.Property<int>("Result")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("CreatedAt");++ b.HasIndex("DavItemId")+ .HasFilter("\"RepairStatus\" = 3");++ b.HasIndex("Result", "RepairStatus", "CreatedAt");++ b.ToTable("HealthCheckResults", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.HealthCheckStat", b =>+ {+ b.Property<long>("DateStartInclusive")+ .HasColumnType("INTEGER");++ b.Property<long>("DateEndExclusive")+ .HasColumnType("INTEGER");++ b.Property<int>("Result")+ .HasColumnType("INTEGER");++ b.Property<int>("RepairStatus")+ .HasColumnType("INTEGER");++ b.Property<int>("Count")+ .HasColumnType("INTEGER");++ b.HasKey("DateStartInclusive", "DateEndExclusive", "Result", "RepairStatus");++ b.ToTable("HealthCheckStats", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.HistoryCleanupItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("HistoryCleanupItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.HistoryItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("Category")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<Guid?>("DownloadDirId")+ .HasColumnType("TEXT");++ b.Property<int>("DownloadStatus")+ .HasColumnType("INTEGER");++ b.Property<int>("DownloadTimeSeconds")+ .HasColumnType("INTEGER");++ b.Property<string>("FailMessage")+ .HasColumnType("TEXT");++ b.Property<string>("FileName")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("JobName")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<long>("TotalSegmentBytes")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("Category");++ b.HasIndex("CreatedAt");++ b.HasIndex("Category", "CreatedAt");++ b.HasIndex("Category", "DownloadDirId");++ b.ToTable("HistoryItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.QueueItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("Category")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("FileName")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("JobName")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<long>("NzbFileSize")+ .HasColumnType("INTEGER");++ b.Property<DateTime?>("PauseUntil")+ .HasColumnType("TEXT");++ b.Property<int>("PostProcessing")+ .HasColumnType("INTEGER");++ b.Property<int>("Priority")+ .HasColumnType("INTEGER");++ b.Property<long>("TotalSegmentBytes")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("Category");++ b.HasIndex("CreatedAt");++ b.HasIndex("FileName")+ .IsUnique();++ b.HasIndex("Priority");++ b.HasIndex("Priority", "CreatedAt");++ b.HasIndex("Category", "Priority", "CreatedAt");++ b.ToTable("QueueItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.QueueNzbContents", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("NzbContents")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("QueueNzbContents", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavItem", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "Parent")+ .WithMany("Children")+ .HasForeignKey("ParentId")+ .OnDelete(DeleteBehavior.Cascade);++ b.Navigation("Parent");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavMultipartFile", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "DavItem")+ .WithOne()+ .HasForeignKey("NzbWebDAV.Database.Models.DavMultipartFile", "Id")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("DavItem");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavNzbFile", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "DavItem")+ .WithOne()+ .HasForeignKey("NzbWebDAV.Database.Models.DavNzbFile", "Id")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("DavItem");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavRarFile", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "DavItem")+ .WithOne()+ .HasForeignKey("NzbWebDAV.Database.Models.DavRarFile", "Id")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("DavItem");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.QueueNzbContents", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.QueueItem", "QueueItem")+ .WithOne()+ .HasForeignKey("NzbWebDAV.Database.Models.QueueNzbContents", "Id")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("QueueItem");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavItem", b =>+ {+ b.Navigation("Children");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/backend/Database/Migrations/20260201023253_Add-HistoryItemId-To-DavItems-Table.cs b/backend/Database/Migrations/20260201023253_Add-HistoryItemId-To-DavItems-Table.csnew file mode 100644index 00000000..31087c9b--- /dev/null+++ b/backend/Database/Migrations/20260201023253_Add-HistoryItemId-To-DavItems-Table.cs@@ -0,0 +1,83 @@+using System;+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace NzbWebDAV.Database.Migrations+{+ /// <inheritdoc />+ public partial class AddHistoryItemIdToDavItemsTable : Migration+ {+ /// <inheritdoc />+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropIndex(+ name: "IX_DavItems_Type_NextHealthCheck_ReleaseDate_Id",+ table: "DavItems");++ migrationBuilder.AddColumn<Guid>(+ name: "HistoryItemId",+ table: "DavItems",+ type: "TEXT",+ nullable: true);++ migrationBuilder.CreateTable(+ name: "HistoryCleanupItems",+ columns: table => new+ {+ Id = table.Column<Guid>(type: "TEXT", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_HistoryCleanupItems", x => x.Id);+ });++ migrationBuilder.CreateIndex(+ name: "IX_DavItems_HistoryItemId",+ table: "DavItems",+ column: "HistoryItemId");++ migrationBuilder.CreateIndex(+ name: "IX_DavItems_Type_HistoryItemId_NextHealthCheck_ReleaseDate_Id",+ table: "DavItems",+ columns: new[] { "Type", "HistoryItemId", "NextHealthCheck", "ReleaseDate", "Id" });++ migrationBuilder.Sql(+ """+ CREATE TRIGGER TR_HistoryItems_Delete_AddHistoryCleanup+ AFTER DELETE ON HistoryItems+ BEGIN+ INSERT INTO HistoryCleanupItems (Id)+ VALUES (OLD.Id);+ END+ """+ );+ }++ /// <inheritdoc />+ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.Sql("DROP TRIGGER IF EXISTS TR_HistoryItems_Delete_AddHistoryCleanup");++ migrationBuilder.DropTable(+ name: "HistoryCleanupItems");++ migrationBuilder.DropIndex(+ name: "IX_DavItems_HistoryItemId",+ table: "DavItems");++ migrationBuilder.DropIndex(+ name: "IX_DavItems_Type_HistoryItemId_NextHealthCheck_ReleaseDate_Id",+ table: "DavItems");++ migrationBuilder.DropColumn(+ name: "HistoryItemId",+ table: "DavItems");++ migrationBuilder.CreateIndex(+ name: "IX_DavItems_Type_NextHealthCheck_ReleaseDate_Id",+ table: "DavItems",+ columns: new[] { "Type", "NextHealthCheck", "ReleaseDate", "Id" });+ }+ }+}diff --git a/backend/Database/Migrations/DavDatabaseContextModelSnapshot.cs b/backend/Database/Migrations/DavDatabaseContextModelSnapshot.csindex ab8b21cb..3f254605 100644--- a/backend/Database/Migrations/DavDatabaseContextModelSnapshot.cs+++ b/backend/Database/Migrations/DavDatabaseContextModelSnapshot.cs@@ -77,6 +77,9 @@ namespace NzbWebDAV.Database.Migrationsb.Property<long?>("FileSize").HasColumnType("INTEGER");+ b.Property<Guid?>("HistoryItemId")+ .HasColumnType("TEXT");+b.Property<string>("IdPrefix").IsRequired().HasColumnType("TEXT");@@ -110,12 +113,14 @@ namespace NzbWebDAV.Database.Migrationsb.HasKey("Id");+ b.HasIndex("HistoryItemId");+b.HasIndex("IdPrefix", "Type");b.HasIndex("ParentId", "Name").IsUnique();- b.HasIndex("Type", "NextHealthCheck", "ReleaseDate", "Id");+ b.HasIndex("Type", "HistoryItemId", "NextHealthCheck", "ReleaseDate", "Id");b.ToTable("DavItems", (string)null);});@@ -220,6 +225,16 @@ namespace NzbWebDAV.Database.Migrationsb.ToTable("HealthCheckStats", (string)null);});+ modelBuilder.Entity("NzbWebDAV.Database.Models.HistoryCleanupItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("HistoryCleanupItems", (string)null);+ });+modelBuilder.Entity("NzbWebDAV.Database.Models.HistoryItem", b =>{b.Property<Guid>("Id")diff --git a/backend/Database/Models/DavItem.cs b/backend/Database/Models/DavItem.csindex 684169e6..59259a83 100644--- a/backend/Database/Models/DavItem.cs+++ b/backend/Database/Models/DavItem.cs@@ -19,6 +19,7 @@ public class DavItempublic DateTimeOffset? ReleaseDate { get; set; }public DateTimeOffset? LastHealthCheck { get; set; }public DateTimeOffset? NextHealthCheck { get; set; }+ public Guid? HistoryItemId { get; set; }public Guid? FileBlobId { get; set; }public static DavItem New@@ -31,6 +32,7 @@ public class DavItemItemSubType subType,DateTimeOffset? releaseDate,DateTimeOffset? lastHealthCheck,+ Guid? historyItemId,Guid? fileBlobId){@@ -50,6 +52,7 @@ public class DavItemNextHealthCheck = releaseDate != null && lastHealthCheck != null? releaseDate.Value + 2 * (lastHealthCheck.Value - releaseDate.Value): null,+ HistoryItemId = historyItemId,FileBlobId = fileBlobId};}diff --git a/backend/Database/Models/HistoryCleanupItem.cs b/backend/Database/Models/HistoryCleanupItem.csnew file mode 100644index 00000000..2f449b6b--- /dev/null+++ b/backend/Database/Models/HistoryCleanupItem.cs@@ -0,0 +1,6 @@+namespace NzbWebDAV.Database.Models;++public class HistoryCleanupItem+{+ public Guid Id { get; set; }+}diff --git a/backend/Program.cs b/backend/Program.csindex b8278365..262ca22d 100644--- a/backend/Program.cs+++ b/backend/Program.cs@@ -86,6 +86,7 @@ class Program.AddHostedService<HealthCheckService>().AddHostedService<ArrMonitoringService>().AddHostedService<BlobCleanupService>()+ .AddHostedService<HistoryCleanupService>().AddHostedService<UsenetFileToBlobstoreMigrationService>().AddScoped<DavDatabaseContext>().AddScoped<DavDatabaseClient>()diff --git a/backend/Queue/FileAggregators/BaseAggregator.cs b/backend/Queue/FileAggregators/BaseAggregator.csindex f1f5c39a..030190de 100644--- a/backend/Queue/FileAggregators/BaseAggregator.cs+++ b/backend/Queue/FileAggregators/BaseAggregator.cs@@ -52,6 +52,7 @@ public abstract class BaseAggregatorsubType: DavItem.ItemSubType.Directory,releaseDate: null,lastHealthCheck: null,+ historyItemId: MountDirectory.HistoryItemId,fileBlobId: null);_directoryCache.Add(pathKey, directory);diff --git a/backend/Queue/FileAggregators/FileAggregator.cs b/backend/Queue/FileAggregators/FileAggregator.csindex fe565542..d6dbfdbf 100644--- a/backend/Queue/FileAggregators/FileAggregator.cs+++ b/backend/Queue/FileAggregators/FileAggregator.cs@@ -34,6 +34,7 @@ public class FileAggregator(DavDatabaseClient dbClient, DavItem mountDirectory,subType: DavItem.ItemSubType.NzbFile,releaseDate: result.ReleaseDate,lastHealthCheck: checkedFullHealth ? DateTimeOffset.UtcNow : null,+ historyItemId: MountDirectory.HistoryItemId,fileBlobId: davNzbFile.Id);diff --git a/backend/Queue/FileAggregators/MultipartMkvAggregator.cs b/backend/Queue/FileAggregators/MultipartMkvAggregator.csindex 15dc5b6a..8c52bee8 100644--- a/backend/Queue/FileAggregators/MultipartMkvAggregator.cs+++ b/backend/Queue/FileAggregators/MultipartMkvAggregator.cs@@ -48,6 +48,7 @@ public class MultipartMkvAggregator(subType: DavItem.ItemSubType.MultipartFile,releaseDate: multipartMkvFile.ReleaseDate,lastHealthCheck: checkedFullHealth ? DateTimeOffset.UtcNow : null,+ historyItemId: MountDirectory.HistoryItemId,fileBlobId: davMultipartFile.Id);diff --git a/backend/Queue/FileAggregators/RarAggregator.cs b/backend/Queue/FileAggregators/RarAggregator.csindex 9620cd9e..61e6dec3 100644--- a/backend/Queue/FileAggregators/RarAggregator.cs+++ b/backend/Queue/FileAggregators/RarAggregator.cs@@ -76,6 +76,7 @@ public class RarAggregator(DavDatabaseClient dbClient, DavItem mountDirectory, bsubType: DavItem.ItemSubType.MultipartFile,releaseDate: fileParts.First().ReleaseDate,lastHealthCheck: checkedFullHealth ? DateTimeOffset.UtcNow : null,+ historyItemId: MountDirectory.HistoryItemId,fileBlobId: davMultipartFile.Id);diff --git a/backend/Queue/FileAggregators/SevenZipAggregator.cs b/backend/Queue/FileAggregators/SevenZipAggregator.csindex 00a5f381..1099b54f 100644--- a/backend/Queue/FileAggregators/SevenZipAggregator.cs+++ b/backend/Queue/FileAggregators/SevenZipAggregator.cs@@ -54,6 +54,7 @@ public class SevenZipAggregator(subType: DavItem.ItemSubType.MultipartFile,releaseDate: sevenZipFile.ReleaseDate,lastHealthCheck: checkedFullHealth ? DateTimeOffset.UtcNow : null,+ historyItemId: MountDirectory.HistoryItemId,fileBlobId: davMultipartFile.Id);diff --git a/backend/Queue/QueueItemProcessor.cs b/backend/Queue/QueueItemProcessor.csindex 009cfc9c..beea8ca4 100644--- a/backend/Queue/QueueItemProcessor.cs+++ b/backend/Queue/QueueItemProcessor.cs@@ -261,6 +261,7 @@ public class QueueItemProcessor(subType: DavItem.ItemSubType.Directory,releaseDate: null,lastHealthCheck: null,+ historyItemId: null,fileBlobId: null);dbClient.Ctx.Items.Add(categoryFolder);@@ -286,6 +287,7 @@ public class QueueItemProcessor(subType: DavItem.ItemSubType.Directory,releaseDate: null,lastHealthCheck: null,+ historyItemId: queueItem.Id,fileBlobId: null);dbClient.Ctx.Items.Add(mountFolder);@@ -310,6 +312,7 @@ public class QueueItemProcessor(subType: DavItem.ItemSubType.Directory,releaseDate: null,lastHealthCheck: null,+ historyItemId: queueItem.Id,fileBlobId: null);dbClient.Ctx.Items.Add(mountFolder);diff --git a/backend/Services/HealthCheckService.cs b/backend/Services/HealthCheckService.csindex a98357bc..a2baeb2b 100644--- a/backend/Services/HealthCheckService.cs+++ b/backend/Services/HealthCheckService.cs@@ -97,7 +97,8 @@ public class HealthCheckService : BackgroundServicepublic static IQueryable<DavItem> GetHealthCheckQueueItemsQuery(DavDatabaseClient dbClient){return dbClient.Ctx.Items- .Where(x => x.Type == DavItem.ItemType.UsenetFile);+ .Where(x => x.Type == DavItem.ItemType.UsenetFile)+ .Where(x => x.HistoryItemId == null);}private async Task PerformHealthCheckdiff --git a/backend/Services/HistoryCleanupService.cs b/backend/Services/HistoryCleanupService.csnew file mode 100644index 00000000..d3d506cd--- /dev/null+++ b/backend/Services/HistoryCleanupService.cs@@ -0,0 +1,53 @@+using Microsoft.EntityFrameworkCore;+using Microsoft.Extensions.Hosting;+using NzbWebDAV.Database;+using Serilog;++namespace NzbWebDAV.Services;++public class HistoryCleanupService : BackgroundService+{+ protected override async Task ExecuteAsync(CancellationToken stoppingToken)+ {+ while (!stoppingToken.IsCancellationRequested)+ {+ try+ {+ await using var dbContext = new DavDatabaseContext();++ // Get the first item from the queue+ var cleanupItem = await dbContext.HistoryCleanupItems+ .FirstOrDefaultAsync(stoppingToken)+ .ConfigureAwait(false);++ // If no items in queue, wait 10 seconds before checking again+ if (cleanupItem == null)+ {+ await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken).ConfigureAwait(false);+ continue;+ }++ // Mark the corresponding dav-items as no longer in History+ await dbContext.Items+ .Where(x => x.HistoryItemId == cleanupItem.Id)+ .ExecuteUpdateAsync(+ x => x.SetProperty(p => p.HistoryItemId, (Guid?)null),+ stoppingToken+ );++ // Remove the cleanup item from the database+ dbContext.HistoryCleanupItems.Remove(cleanupItem);+ await dbContext.SaveChangesAsync(stoppingToken).ConfigureAwait(false);++ // Continue immediately to next iteration to process more items+ }+ catch (Exception e)+ {+ Log.Error(e, $"Error processing history cleanup queue: {e.Message}");++ // Wait 10 seconds before continuing on exception+ await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken).ConfigureAwait(false);+ }+ }+ }+}\ No newline at end of file