From 075f690419fc4fa0c706dfbdf1797e35a02f7a7e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 18 Oct 2026 15:41:58 -0500 Subject: update Find() to accept only an id (remove footgun) --- .../API/Controllers/TransfersController.cs | 2 +- src/slskd/Transfers/Uploads/UploadService.cs | 24 ++++++++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/slskd/Transfers/API/Controllers/TransfersController.cs b/src/slskd/Transfers/API/Controllers/TransfersController.cs index 83eb04ef..3dd2f124 100644 --- a/src/slskd/Transfers/API/Controllers/TransfersController.cs +++ b/src/slskd/Transfers/API/Controllers/TransfersController.cs @@ -709,7 +709,7 @@ namespace slskd.Transfers.API return BadRequest(); } - var upload = Transfers.Uploads.Find(t => t.Id == guid); + var upload = Transfers.Uploads.Find(guid); if (upload == default) { diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index 4361ece1..c72c96ee 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -96,11 +96,11 @@ namespace slskd.Transfers.Uploads Task UploadAsync(Transfer transfer, CancellationToken cancellationToken = default); /// - /// Finds a single upload matching the specified . + /// Finds a single upload matching the specified . /// - /// The expression to use to match uploads. + /// The unique identifier of the upload. /// The found transfer, or default if not found. - Transfer Find(Expression> expression); + Transfer Find(Guid id); /// /// Gets upload statistics for the specified . @@ -306,7 +306,7 @@ namespace slskd.Transfers.Uploads we're not using DbContext and tracked changes here because we don't want to hold a connection open for the duration of the upload */ - transfer = Find(t => t.Id == transfer.Id) + transfer = Find(transfer.Id) ?? throw new TransferNotFoundException($"Transfer with ID {transfer.Id} not found"); if (transfer.State != (TransferStates.Queued | TransferStates.Locally)) @@ -804,21 +804,15 @@ namespace slskd.Transfers.Uploads } /// - /// Finds a single upload matching the specified . + /// Finds a single upload matching the specified . /// - /// The expression to use to match uploads. + /// The unique identifier of the upload. /// The found transfer, or default if not found. - public Transfer Find(Expression> expression) + public Transfer Find(Guid id) { try { - using var context = ContextFactory.CreateDbContext(); - - return context.Transfers - .AsNoTracking() - .Where(t => t.Direction == TransferDirection.Upload) - .Where(expression) - .SingleOrDefault(); + return Query(q => q.Where(t => t.Id == id), includeRemoved: true).SingleOrDefault(); } catch (Exception ex) { @@ -1111,7 +1105,7 @@ namespace slskd.Transfers.Uploads private bool TryFail(Guid id, string exception, TransferStates state) { - var t = Find(t => t.Id == id); + var t = Find(id); if (t is null) { -- cgit v1.2.3