From e7c37e1dba12e7a23f4bf0217be40afb2584e480 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 27 Sep 2025 16:04:44 -0500 Subject: formatting --- src/slskd/Transfers/Downloads/DownloadService.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 63b04394..318c4e43 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -155,11 +155,11 @@ namespace slskd.Transfers.Downloads using var context = ContextFactory.CreateDbContext(); var existing = context.Transfers - .Where(t => t.Direction == TransferDirection.Download) - .Where(t => t.Username == transfer.Username) - .Where(t => t.Filename == transfer.Filename) - .Where(t => !t.Removed) - .FirstOrDefault(); + .Where(t => t.Direction == TransferDirection.Download) + .Where(t => t.Username == transfer.Username) + .Where(t => t.Filename == transfer.Filename) + .Where(t => !t.Removed) + .FirstOrDefault(); if (existing != default) { -- cgit v1.2.3 From 20fa256fb60cf37943da1e8187112682ecf24c0a Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 27 Sep 2025 16:18:19 -0500 Subject: refactor progress updates --- src/slskd/Transfers/Downloads/DownloadService.cs | 31 +++++++++++++++++++--- src/slskd/Transfers/Uploads/UploadService.cs | 33 +++++++++++++++++++++--- 2 files changed, 57 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 318c4e43..ef8e84bf 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -283,10 +283,35 @@ namespace slskd.Transfers.Downloads }, progressUpdated: (args) => rateLimiter.Invoke(() => { - transfer = transfer.WithSoulseekTransfer(args.Transfer); + // don't do anything unless the `transfer` within the outer scope is in the + // InProgress state; this will help prevent out-of-band updates that are sometimes + // being made after the transfer is completed, causing them to appear 'stuck' + if (transfer.State == TransferStates.InProgress) + { + syncRoot.Wait(cts.Token); - // todo: broadcast to signalr hub - SynchronizedUpdate(transfer); + try + { + // check again to see if the state changed while we were waiting to obtain the lock + if (transfer.State == TransferStates.InProgress) + { + // update only the properties that we expect to change between progress updates + // this helps prevent this update from 'stepping' on other updates + transfer.BytesTransferred = args.Transfer.BytesTransferred; + transfer.AverageSpeed = args.Transfer.AverageSpeed; + + using var context = ContextFactory.CreateDbContext(); + + context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter + .SetProperty(t => t.BytesTransferred, transfer.BytesTransferred) + .SetProperty(t => t.AverageSpeed, transfer.AverageSpeed)); + } + } + finally + { + syncRoot.Release(); + } + } })); var completedTransfer = await Client.DownloadAsync( diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index 6209f3da..6db9f6a5 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -329,10 +329,35 @@ namespace slskd.Transfers.Uploads }, progressUpdated: (args) => rateLimiter.Invoke(() => { - transfer = transfer.WithSoulseekTransfer(args.Transfer); - - // todo: broadcast - SynchronizedUpdate(transfer); + // don't do anything unless the `transfer` within the outer scope is in the + // InProgress state; this will help prevent out-of-band updates that are sometimes + // being made after the transfer is completed, causing them to appear 'stuck' + if (transfer.State == TransferStates.InProgress) + { + syncRoot.Wait(cts.Token); + + try + { + // update only the properties that we expect to change between progress updates + // this helps prevent this update from 'stepping' on other updates + transfer.BytesTransferred = args.Transfer.BytesTransferred; + transfer.AverageSpeed = args.Transfer.AverageSpeed; + + // check again to see if the state changed while we were waiting to obtain the lock + if (transfer.State == TransferStates.InProgress) + { + using var context = ContextFactory.CreateDbContext(); + + context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter + .SetProperty(t => t.BytesTransferred, args.Transfer.BytesTransferred) + .SetProperty(t => t.AverageSpeed, args.Transfer.AverageSpeed)); + } + } + finally + { + syncRoot.Release(); + } + } }), seekInputStreamAutomatically: false, disposeInputStreamOnCompletion: true, // note: don't set this to false! -- cgit v1.2.3