Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Simplified removal of history items.

nzbdav-devbf6bb11c600e
diff --git a/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryController.cs b/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryController.cs
index f4198b0a..c0f2f01a 100644
--- a/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryController.cs
+++ b/backend/Api/SabControllers/RemoveFromHistory/RemoveFromHistoryController.cs
@@ -15,10 +15,8 @@ public class RemoveFromHistoryController(
{
public async Task<RemoveFromHistoryResponse> RemoveFromHistory(RemoveFromHistoryRequest request)
{
- await using var transaction = await dbClient.Ctx.Database.BeginTransactionAsync().ConfigureAwait(false);
await dbClient.RemoveHistoryItemsAsync(request.NzoIds, request.DeleteCompletedFiles, request.CancellationToken).ConfigureAwait(false);
await dbClient.Ctx.SaveChangesAsync(request.CancellationToken).ConfigureAwait(false);
- await transaction.CommitAsync(request.CancellationToken).ConfigureAwait(false);
_ = websocketManager.SendMessage(WebsocketTopic.HistoryItemRemoved, string.Join(",", request.NzoIds));
return new RemoveFromHistoryResponse() { Status = true };
}
diff --git a/backend/Database/DavDatabaseClient.cs b/backend/Database/DavDatabaseClient.cs
index 2e943e2e..91494c4c 100644
--- a/backend/Database/DavDatabaseClient.cs
+++ b/backend/Database/DavDatabaseClient.cs
@@ -198,17 +198,14 @@ public sealed class DavDatabaseClient(DavDatabaseContext ctx)
{
if (deleteFiles)
{
- await Ctx.Items
- .Where(d => Ctx.HistoryItems
- .Where(h => ids.Contains(h.Id) && h.DownloadDirId != null)
- .Select(h => h.DownloadDirId!)
- .Contains(d.Id))
- .ExecuteDeleteAsync(ct).ConfigureAwait(false);
+ var historyItems = await Ctx.HistoryItems.Where(x => ids.Contains(x.Id)).ToListAsync(ct);
+ foreach (var historyItem in historyItems.Where(h => h.DownloadDirId is not null))
+ Ctx.Items.Remove(new DavItem() { Id = historyItem.DownloadDirId!.Value });
+ Ctx.HistoryItems.RemoveRange(historyItems);
+ return;
}
- await Ctx.HistoryItems
- .Where(x => ids.Contains(x.Id))
- .ExecuteDeleteAsync(ct).ConfigureAwait(false);
+ Ctx.HistoryItems.RemoveRange(ids.Select(id => new HistoryItem() { Id = id }));
}
private class FileSizeResult