diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-10-10 09:31:58 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-10-10 09:31:58 -0500 |
| commit | b5b4f6d7cbc1bdfaa0c4b659030872e83facafdb (patch) | |
| tree | d826b561bdc1823bc55a14598ea04120100a116c /src | |
| parent | e66714d0d51552b7228e5deeb4c08d1f2c9c49e3 (diff) | |
| download | slskd-b5b4f6d7cbc1bdfaa0c4b659030872e83facafdb.tar.gz | |
prime the peer connection cache before starting downloads
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Transfers/Downloads/DownloadService.cs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 6a149ff8..c8f82167 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -25,6 +25,8 @@ namespace slskd.Transfers.Downloads using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; + using System.Net; + using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -477,7 +479,7 @@ namespace slskd.Transfers.Downloads /// <exception cref="ArgumentException">Thrown when the username is null or an empty string.</exception> /// <exception cref="ArgumentException">Thrown when no files are requested.</exception> /// <exception cref="AggregateException">Thrown when at least one of the requested files throws.</exception> - public Task<(List<Transfer> Enqueued, List<Transfer> Failed)> EnqueueAsync(string username, IEnumerable<(string Filename, long Size)> files, CancellationToken cancellationToken = default) + public async Task<(List<Transfer> Enqueued, List<Transfer> Failed)> EnqueueAsync(string username, IEnumerable<(string Filename, long Size)> files, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(username)) { @@ -613,6 +615,17 @@ namespace slskd.Transfers.Downloads return (enqueued, failed); } + // prime the cache for this user, to 1) make sure we can connect, and 2) avoid needing to race for it in the loop + try + { + await Client.ConnectToUserAsync(username, invalidateCache: false, cancellationToken); + } + catch (Exception ex) + { + Log.Error(ex, "Failed to connect to {Username}: {Message}", username, ex.Message); + throw; + } + /* the files are all now in the database in the Queued | Locally state. @@ -794,7 +807,7 @@ namespace slskd.Transfers.Downloads Log.Error(task.Exception, "Task for enqueue of {Count} files from {Username} did not complete successfully: {Error}", files.Count(), username, task.Exception.Flatten().Message); }, cancellationToken: CancellationToken.None); - return Task.FromResult((enqueued, failed)); + return (enqueued, failed); } finally { |
